Chrome浏览器超时后Element.scrollIntoView无法正常工作

Yas*_*son 5 javascript google-chrome js-scrollintoview

使用scrollIntoView时,我遇到了一个非常奇怪的问题。在Safari和Chrome中,当我打开新窗口或新标签时,代码有效,但在按下Refresh按钮时,代码无效。在Firefox中,它始终有效。当我使用setTimeout()Refresh按钮触发这样所有的浏览器滚动:

setTimeout( function () {scrollToSelection();}, 1);
Run Code Online (Sandbox Code Playgroud)

setTimeout( function () {scrollToSelection();}, 1);
Run Code Online (Sandbox Code Playgroud)
scrollToSelection = function() {
  var element = document.querySelector('p');
  element.scrollIntoView();
};
Run Code Online (Sandbox Code Playgroud)
p {
  margin-top: 1000px;
}
Run Code Online (Sandbox Code Playgroud)

任何想法可能是什么原因造成的?