简体   繁体   English

浏览器在单独的选项卡中时setInterval排队

[英]setInterval queuing up while browser in separate tab

How can i stop Javascript from queuing up animations from a setInterval while the page is not the primary tab in view? 当页面不是视图中的主要选项卡时,如何阻止Javascript从setInterval排队动画? I've tried clearing the interval on blur of the document but no luck. 我尝试清除文档模糊的间隔,但是没有运气。

Have you tried using window.onblur and window.onfocus ? 您是否尝试过使用window.onblurwindow.onfocus

They should dot he trick 他们应该点他的把戏

In modern browsers you don't have to care about this, because the browser will automatically increase the interval to 1 second if the tab is in the background. 在现代的浏览器中,您不必担心,因为如果选项卡在后台,浏览器会自动将间隔增加到1秒。 Reference for Firefox . Firefox参考。

As Martin stated. 正如马丁所说。

Use window.onblur and window.onfocus to pause/unpause the setinterval or atleast the contents inside. 使用window.onblurwindow.onfocus可以暂停/取消暂停setinterval或至少保留其中的内容。

For example. 例如。

Use window.onblur to set var away = true; 使用window.onblur设置var away = true;

Then in the setinterval you put a if(!away){...your code here...} this way the animations will not be triggered when the interval passes. 然后,在setinterval您将if(!away){...your code here...}放置为以这种方式在间隔过去时不会触发动画。

EDIT 编辑

Remember to also put a window.onfocus to set var away = false; 记住还要放置一个window.onfocus来设置var away = false;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript 在切换浏览器选项卡时设置Interval 执行延迟 - Javascript SetInterval execution delay in while switch browser tab 标签重新获得焦点后SetInterval赶上来 - SetInterval catching up after tab regains focus 如何在浏览器选项卡处于焦点时运行setInterval? - How to make setInterval run when browser tab is on focus? 当浏览器选项卡未聚焦时,Javascript setInterval / setTimeout不起作用 - Javascript setInterval/setTimeout not working when browser tab not focused 当浏览器选项卡为背景时,setInterval 无故停止 - setInterval stops without any reason when browser tab is background 在单独的选项卡中向浏览器提醒用户活动 - Alert user in browser of activity in separate tab 如果两个单独的选项卡有两个单独的弹出窗口,那么在关闭弹出窗口时如何刷新各自的选项卡。 如果我在其他活动标签中 - In case of two separate pop-ups from two separate tabs, how can I refresh the respective tab while closing a pop-up. if I am in a different active tab 使用useEffect时标签不活动时如何停止setInterval? - How to stop setInterval when tab is not active while using useEffect? 即使选项卡没有焦点或浏览器处于睡眠状态,我如何运行 setInterval 或秒表系统? | 反应和下一个 Js - How can I run setInterval or a stopwatch system even tab is not focus or browser in sleep? | React & Next Js 如何在单独的浏览器选项卡中显示Node .get()响应? - How to display Node .get() response in a separate browser tab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM