This (in my experience) is the most accurate way to get timers as close to the clock as possible:
// get current time in msecs to nearest 30 seconds var msecs = new Date().getTime() % 30000; // wait until the timeout setTimeout(callback, 30000 - msecs);
Then, in the callback, once everything is done, repeat the same thing to trigger the next event.
Using setInterval causes other problems, including clock drift. The calculation based on the current time takes into account the execution time of the callback itself.
You will also need to use Date().getTime() to figure out which frame of your animation to show.
Everything will look something like this:
function redraw() { var interval = 30000;
working demo http://jsfiddle.net/alnitak/JPu4R/
source share