锚点定位

<div id="myId"></div>
<script>
let ids = "#myId";
    if(ids){
    const decoded = decodeURIComponent(ids);
    const ele = document.getElementById(decoded);
    if(ele){
    //window.location.hash = decoded;//设置hash锚点(兼容浏览器)
    ele.scrollIntoView({
    behavior:'smooth',
    block:'start',
    })
    }
    }

</script>

 

posted @ 2025-11-21 10:55  木樨园  阅读(0)  评论(0)    收藏  举报