方法原作者:http://www.learningjquery.com

//页内锚点滑动效果,来自http://www.learningjquery.com/的方法

$('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; //使其呈现清晰的URL链接
            }
    }
});

发现网上这段代码被各个站粘贴,以致我也不太清楚原作是谁了,我还是比较相信国外的那些大牛,不过这段代码确实值得转帖分享,在本小站再次分享。