Thomas Van Nuffel
Thomas Van Nuffel

Reputation: 199

jquery animation freaks out in background

I have made a little animation that resembles the coverflow itunes uses as a screensaver on mac. It fetches a list with filenames using ajax and starts looping over them to randomly fill divs with them.

Demo code: http://jsfiddle.net/FQmXK/4/

All of this works great but the problem starts when you minimize the browser or go to a different tab on google chrome. The animation seems to queue up a bunch of cycles and tries to execute them all when the window is opened up again. This is causing all sorts of problems, images being undefined, all kinds of flashing on the screen...

I was wondering if there is any established solution for this queueing behavior? Can I force it to execute all animation even if its not visible?

Upvotes: 1

Views: 563

Answers (2)

thirtydot
thirtydot

Reputation: 228202

This question discusses the same problem and provides a generalized solution:

How can I make setInterval also work when a tab is inactive in Chrome?

Upvotes: 1

DhruvPathak
DhruvPathak

Reputation: 43245

You can detect browser window focus : Is there a way to detect if a browser window is not currently active?

And set a variable. If the window is inactive, set a variable to false, and do not queue further animations until the window becomes active.

Upvotes: 1

Related Questions