浏览器选项卡隐藏/显示的事件? [英] Event for browser tab hidden/shown?
问题描述
浏览器选项卡丢失/获得焦点时是否有任何DOM事件?我知道在 我之所以要这样做,是因为我运行的动画可能会消耗相当多的CPU时间。当浏览器选项卡不可见时,没有理由继续动画。现在我知道现在的浏览器减少了后台标签的定时器分辨率,但是我实际上可以暂停动画,这样就不会消耗任何CPU时间。 如果你是想知道,这就是我写的: 至少Google Chrome支持 Is there any DOM event for when the browser tab loses/gains focus? I know there are the The reason why I want this is because I run animations that might consume quite some CPU time. When the browser tab is not visible there is no reason to continue animating. Now I know that modern browsers reduce the timer resolution of background tabs, but I could actually pause the animation, so that no CPU time whatsoever is consumed. In case you are wondering, this is what I'm writing:
http://panzi.github.com/Browser-Ponies/ At least Google Chrome supports a 这篇关于浏览器选项卡隐藏/显示的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!窗口
上有 blur 和
焦点
,但是当浏览器窗口整体失去焦点时,它们也会被触发。浏览器可能对用户仍然可见。当然,这样的事件将是浏览器的具体情况,但没关系。
http://panzi.github.com/ Browser-Ponies / webkitvisibilitychange
event和一个 document.webkitHidden
属性。请参阅可见性API 。但似乎只有在显示的选项卡更改时才触发,而不是整个窗口最小化时触发。对于Internet Explorer,似乎还有一个 visibilitychange
事件,但文档没有提到任何相关信息。blur
and focus
events on window
, but they also fire when the browser window as a whole loses focus. The browser might then be still visible to the user. Of course such an event would be browser specific, but that's ok.webkitvisibilitychange
event and a document.webkitHidden
property. See the visibility API. But it seems only to fire when the shown tab changes, not when the whole window is minimized. There also seems to be a visibilitychange
event for Internet Explorer, but the documentation doesn't say anything about it.