【发布时间】:2014-08-13 21:50:50
【问题描述】:
我正在使用 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 应用溢出值之前,它可以完美运行。比如我关闭一个模态窗口后,这段代码负责隐藏水平溢出并将垂直溢出设置为自动:
$('.file-content a.close-reveal-modal').on('click', function() {
$('html, body').css({
'overflow-y' : 'auto',
'overflow-x' : 'hidden'
});
});
应用这些值后,动画滚动到锚链接的插件停止工作,单击它们不会产生任何结果。如果我在关闭模式时删除负责设置溢出的代码,Chris 的插件每次都会像魅力一样工作。
为什么会这样?
非常感谢任何形式的帮助!
【问题讨论】:
-
你发现了吗?
标签: javascript jquery html css scroll