[英]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.onblur
和window.onfocus
?
They should dot he trick 他们应该点他的把戏
As Martin stated. 正如马丁所说。
Use window.onblur
and window.onfocus
to pause/unpause the setinterval
or atleast the contents inside. 使用window.onblur
和window.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.