一个简单的jquery页面内跳转

来源:互联网 发布:八度网络论坛 编辑:程序博客网 时间:2024/05/21 16:58

<script>


$(function(){
    $('a[href*=#]').click(function() {
    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;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
});

</script>


<a herf="a"></a>


<div id="a">nihao</div>

0 0
原创粉丝点击