0

I am building a jQuery app using animation.

Currently the requestAnimationFrame API pauses the animating if I minimize my browser or change browser tab, then when I come back to my application it starts again.

Would it be possible to avoid this pause so the animation keeps running when I leave the current tab?

sam-w
  • 7,478
  • 1
  • 47
  • 77
  • 1
    Which version of jQuery are you using? Support for `requestAnimationFrame()` was removed some time ago due to the very problem you describe (see [this question](http://stackoverflow.com/questions/7999680/why-doesnt-jquery-use-requestanimationframe) and [bug #9381](http://bugs.jquery.com/ticket/9381)). Chances are you just have to upgrade. – Frédéric Hamidi Dec 05 '12 at 15:35

1 Answers1

1

This is exactly the intended behaviour of requestAnimationFrame; to request a frame when the browser is focused on the tab that the script is running in. If you need an animation to be constantly running then you'll want to use setInterval instead.

var FPS = 30;
setInterval(function()
{
  draw();
}, 1000/FPS);
Ben
  • 10,106
  • 3
  • 40
  • 58