4

我有以下 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。

如何做到这一点?

4

1 回答 1

13

尝试...

$('html, body').stop().animate({
    'scrollTop': $target.offset().top-140
}, 900, 'swing', function () {
    window.location.hash = target;
});
于 2013-10-24T17:58:27.823 回答