By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,483 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,483 IT Pros & Developers. It's quick & easy.

Erratic behaviour of setInterval in animation

P: 2
I'm using setInterval to animate an array of weather images. The code works, but in FF, sometimes the event fires too soon, giving the impression that images are missed, while in IE, the script works fine. I think that I'm doing something wrong, but I have the impression (but maybe false) that it worked fine in FF up until a few updates ago. Is this a FF bug? The basic code is this:
Expand|Select|Wrap|Line Numbers
  1. var interval_id = window.setInterval("next_frame()",interval_delay);
  2. function next_frame() {
  3.    document.images["image_holder"].src = image_array[frame_number].src;
  4.    document.getElementById("date_holder").innerHTML = date_array[frame_number];
  5.    if (fish) {
  6.       frame_number++;
  7.       if (frame_number == image_array.length) {
  8.          if (hold > 1) {
  9.             hold--;
  10.             frame_number--;
  11.          }
  12.          else {
  13.             if (cycle == 0) {
  14.                hold = pole;
  15.               }
  16.             frame_number = 0;
  17.          }
  18.       }
  19.    }
  20. }
One working example is at:
Jul 10 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 5,343
hmmm ... i don't get that 'impression' ... it seems that the code is working without any problems in FF 3 ...

just a note: don't use that ugly eval like function-references in the setInterval or setTimeout methods ...

Expand|Select|Wrap|Line Numbers
  1. var interval_id = window.setInterval("next_frame()",interval_delay);
is equivalent to:

Expand|Select|Wrap|Line Numbers
  1. var interval_id = window.setInterval(next_frame, interval_delay);
the first param is a function-reference that just could be passed by its name.

kind regards
Jul 10 '08 #2

P: 2
Thanks for looking at this. Maybe it works correctly in FF3 (I'm using FF2.0.0.15), but would you mind comparing the behavior in FF3 to IE, please? I see the sequence unevenly time spaced in my FF, but correct in IE. I just updated the php code as you suggested, BTW. Thanks for the info.
Jul 10 '08 #3

Expert Mod 5K+
P: 5,343
i compared it and i didn't even see it? maay be its a cache-handling issue, so that IE uses the cached ones while FF reloads them? you could preload the images on pageload ...

btw. it was javascript code ;)

kind regards
Jul 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.