jQuery Smooth Scroll Offset

时间:2013-10-24 17:49:34

标签: 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。

如何实现这一目标?

1 个答案:

答案 0 :(得分:12)

...试

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