Javascript body.scrollTop在严格模式下不推荐使用。
我想要一个平滑的滚动到内部链接。在firefox中可以正常工作,但在Chrome中出现错误“body.scrollTop在严格模式下不推荐使用” 我的密码是Javascript body.scrollTop在严格模式下不推荐使用。,javascript,jquery,google-chrome,Javascript,Jquery,Google Chrome,我想要一个平滑的滚动到内部链接。在firefox中可以正常工作,但在Chrome中出现错误“body.scrollTop在严格模式下不推荐使用” 我的密码是 $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && loca
$(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;
}
}
});
});
然而,问题是在我改变了这一点之后
$('html,body').animate({scrollTop:target.offset().top},1000)代码>
到
$('html').animate({scrollTop:target.offset().top},1000)代码>
链接根本不起作用,控制台中也没有错误/警告 保留'html,body'
以面向更多浏览器
只要Chrome显示“弃用”警告(不是错误),它仍然会响应body.scrollTop,并且应该像您预期的那样滚动
我认为混淆是因为Chrome 32警告了不推荐的功能,而Chrome 33只使用了不推荐的功能,没有警告。可能重复:@RyanPilbeam提到的解决方案是将$('html,body')更改为$('html'),这正是我的问题-旧代码在Firefox中工作,而不是在Chrome中,但是在更改它之后,它在这两种情况下都不起作用,没有错误/警告。我无法想象为什么DOM属性会出现严格的模式错误……而且我在Chrome中没有遇到这种错误。你在使用哪个版本的jQuery和Chrome?@cookiemonster在那把小提琴上得到了同样的警告。jQuery 2.1.0,Chrome版本32.0.1700.107 m。