jQuery应用overflow值后scrollTop()无法工作?

3

我正在使用Chris Coyier的插件(实际上是Devin Sturgeon修改过的版本)来动画滚动到锚链接:

// Easing for links pointing to anchors
$(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;
      }
    }
  });
});

在没有使用jQuery添加overflow属性的情况下,它可以完美运行。例如,在关闭模态窗口后,下面这段代码将负责隐藏水平溢出并将垂直溢出设置为自动:

$('.file-content a.close-reveal-modal').on('click', function() {
  $('html, body').css({
    'overflow-y' : 'auto',
    'overflow-x' : 'hidden'
  });
});

应用这些值后,滚动到锚点链接的插件就停止工作了,单击它们不会产生任何结果。如果删除负责在关闭模态时设置溢出的代码,则Chris的插件每次都能完美运行。

为什么会发生这种情况呢?

非常感谢您的任何帮助!


你解决了这个问题吗? - arao6
1个回答

2

你可能想知道,Beri,Stackoverflow Netiquette 不鼓励使用 URL 链接来引用帖子。相反,最好在你的帖子中包含相关信息,这样即使所引用的页面不再存在,也能提供你想要表达的内容。你可能需要重新阅读 StackOverflow 的 Do's 和 Don't-s,并重新编辑你的帖子,以展示你遵守社区礼仪的意愿,并避免任何版主采取必要措施执行规则。祝你享受这个伟大的社区,成为其中的贡献者。 - user3666197

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接