【问题标题】:Scroll to div but with margin difference滚动到 div 但有边距差异
【发布时间】:2013-11-21 11:57:07
【问题描述】:

使用我的 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;
              }
        }
    });
});

有人能让10pxdiv 高吗?非常感谢

如果您想更具体地了解http://www.sventasticable.nl 的问题,这是我的网页

我的英语不是很好。

【问题讨论】:

    标签: javascript html margin pixels


    【解决方案1】:

    top 中删除 10

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

    【讨论】:

      猜你喜欢
      • 2013-11-20
      • 2014-06-21
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多