菜单在div之前滚动到X px

时间:2015-04-26 17:37:56

标签: jquery html scroll

我真的不知道如何解释我的意思,但请耐心等待。 所以,我得到这个脚本让我的菜单滚动到我的单页网站上的div:

    $(document).ready(function(){
        $('a[href*=#]:not([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) {
                $('html,body').animate({
                scrollTop: target.offset().top
                }, 1000);
                return false;
            }
            }
        });
    });

它完美地工作但是因为我在顶部有一个固定的菜单,我得到菜单本身所覆盖的目标div的50px。

我想知道是否有任何方法可以让它在目标之前滚动到50px。

我在jquery,我真的很感激一些帮助。

1 个答案:

答案 0 :(得分:2)

你的意思是......

(target.offset().top - 50)