jQuery 平滑滚动偏移量



>我有以下jQuery代码

$(document).ready(function(){
    $('a[href^="#"]').on('click',function (e) {
        e.preventDefault();
        var target = this.hash,
        $target = $(target);
        $('html, body').stop().animate({
            'scrollTop': $target.offset().top
        }, 900, 'swing', function () {
            window.location.hash = target;
        });
    });
});

这是一个滚动插件,可以平滑地向下滚动到页面中的内部链接。我想将学校偏移 -140px,这样它就不会直接滚动到 DIV。

如何实现这一点?

试试...

$('html, body').stop().animate({
    'scrollTop': $target.offset().top-140
}, 900, 'swing', function () {
    window.location.hash = target;
});

最新更新