Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 body.scrollTop在严格模式下不推荐使用。_Javascript_Jquery_Google Chrome - Fatal编程技术网

Javascript 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

我想要一个平滑的滚动到内部链接。在firefox中可以正常工作,但在Chrome中出现错误“body.scrollTop在严格模式下不推荐使用”

我的密码是

$(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。