Saturday 15 January 2011

javascript - requestAnimationFrame and knowing when the browser is re-painting? -


Is there a way to find out that the browser is actively using requestAnimationFrame ? P> For example when I switch from tab to one running requestAnimationFrame , the function closes, when I turn it back on, the best way to deal with it What is it?

If requestAnimationFrame is running 100% then you can check that :

  window.addEventListener ('blur', function () {// full not running}, false);   

and

  window.addEventListener ('focus', function) (// optimal running (if used)}, false) ;   

This can be detected as we know the requestAnimationFrame trigger rate (in most browsers) reduces when the window (tab) is not active ( IF is being used - it really depends on the code requestAnimationFrame ).

If you want to run it continuously, then you can insert a mechanism like this:

  var isActiveTab = true; // function myLoop () {// Update with the events above my cool stuff is here (ifActiveTab) {requestAnimationFrame (myLoop); } Else {setTimeout (myLoop, 16); // Apply force (vblank sync is not required / when the display is not updated}}   

Note that the rate reduction for requestAnimationFrame is not part of the standard and it is a browser Exclusive is the implementation.

No comments:

Post a Comment