【发布时间】:2021-02-16 14:56:56
【问题描述】:
当页面隐藏时,Chrome 永远不会触发滚动事件,尽管页面实际上正在滚动。这看起来像是他们为减少不可见页面的 CPU 和网络使用而实施的。
有没有办法解决这种行为,即使使用 Chrome 的标志或扩展程序?我需要触发“滚动”事件,因为这是我正在测试的。
setInterval(() => {
window.scrollBy(0, 100);
// scrolls indefinitely even when the page is hidden
}, 1000);
addEventListener("scroll", () => {
console.log("scroll " + document.documentElement.scrollTop);
// however, this gets fired only if document.hidden is false
});
【问题讨论】:
标签: javascript google-chrome dom visibilitychange