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

猜你喜欢

转载自www.cnblogs.com/xinghong/p/11398514.html
07