07 - 页面内锚点的平滑跳转效果

 // 锚点跳转平滑移动
    $(document).ready(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;
                }
            }
        });
    });

 参考:https://www.cnblogs.com/wgwyanfs/p/6821813.html

posted @ 2019-08-23 10:28  星鸿  阅读(428)  评论(0编辑  收藏  举报