window.scrollTo 在 Internet Explorer 11 中不起作用

Tan*_*anu 5 javascript jquery

我希望在启动页面时滚动条默认位于顶部。但是下面的代码在 chrome 中工作正常,但在 IE11 中不行。

如果我尝试调试脚本,滚动条位于顶部。

$(document).ready(function () {
  window.scrollTo(0,0);
 }
Run Code Online (Sandbox Code Playgroud)

我在网上尝试了不同的解决方案,例如

$(window).scroll().scrollTop(0);
document.body.scrollTop(0);
Run Code Online (Sandbox Code Playgroud)

但在 IE 中没有任何效果。请帮助我

Ran*_*los 3

尝试使用

$('body,html').scroll().scrollTop(0);
Run Code Online (Sandbox Code Playgroud)

或者

$('body,html').animate({scrollTop:0});
Run Code Online (Sandbox Code Playgroud)

  • 我尝试了你的代码,但在 IE 中仍然不起作用。我还清除了浏览器缓存。我仍然面临同样的问题 (2认同)