Background Tab Animation and jQuery

a 夏天 提交于 2019-12-24 05:13:23

问题


See Code: http://jsbin.com/amavud/2

Problem: In browsers which implement requestAnimationFrame, when tab with animation is set to background (new tab opened), animation timing is borked.

Question: My understanding of requestAnimationFrame is that animation should stop when moved to a background tab, but from this example, it seems like webkit browsers complete the current animation and THEN stop.

The problem seems to come from the fact that the second and third balls need a delay before moving, requiring a setTimeout. Is there a problem with the way requestAnimationFrame is implemented in jQuery, or am I just coding this wrong?

I've tried to follow the advice on http://api.jquery.com/animate/ using delay() and queue(), but can't seem to get the right effect.


回答1:


I don't think is the way you're coding but the fact that requestAnimationFrame is NOT working in background, so it stops. Or at least this is what Paul Irish is saying in bold "if you're running the animation loop in a tab that's not visible, the browser won't keep it running". http://paulirish.com/2011/requestanimationframe-for-smart-animating/

Since this js is not even working in any browser I don't know why you want to implement it.




回答2:


Using an old version of jQuery before requestAnimationFrame (1.4.2). Seems wrong. I don't think rAF is properly implemented yet.



来源:https://stackoverflow.com/questions/6737273/background-tab-animation-and-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!