文章出處

點擊a鏈接時,跳轉到相應id的位置處,有一個滑動效果。

<a href="#my">我是跳轉到div</a>
<div id="my"></div>
<
script> $(function(){ //錨點跳轉滑動效果 $('a[href*=#],area[href*=#]').click(function() { console.log(this.pathname) if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']'); if ($target.length) { var targetOffset = $target.offset().top-50; $('html,body').animate({ scrollTop: targetOffset }, 1000); return false; } } }); }) </script>

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()