jQuery实现锚点与链接之间的平滑滚动

2014/4/29 4:25:00jQueryjs
$(function(){   
    $('a[href*=#],area[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
                },
                500);
                return false;
            }
        }
    });
})

本文由我的原始笔记迁移而来:原始链接

https://www.cnblogs.com/jsoncode/p/3699515.html