Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 滚动至div,但有边距差_Javascript_Html_Margin_Pixels - Fatal编程技术网

Javascript 滚动至div,但有边距差

Javascript 滚动至div,但有边距差,javascript,html,margin,pixels,Javascript,Html,Margin,Pixels,使用我的javascript代码,我可以滚动到一个div,但我需要javascript使我比该div高20像素 $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostna

使用我的javascript代码,我可以滚动到一个div,但我需要javascript使我比该div高20像素

$(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高出10px吗?多谢各位

这是我的网页,如果你想知道更具体的问题


我的英语不是很好。

top

$('html,body').animate({
      scrollTop: target.offset().top - 10
    }, 1000);