菜单滚动到 div 之前的 X 像素

Menu scroll to X px before div

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

    $(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 的 50 像素。

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

我在 jquery 是 0,非常感谢您的帮助。

你的意思是……

(target.offset().top - 50)