Erratic behaviour of setInterval in animation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • strangeplant
    New Member
    • Jul 2008
    • 2

    Erratic behaviour of setInterval in animation

    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:
    Code:
    var interval_id = window.setInterval("next_frame()",interval_delay);
    function next_frame() {
       document.images["image_holder"].src = image_array[frame_number].src;
       document.getElementById("date_holder").innerHTML = date_array[frame_number];
       if (fish) {
          frame_number++;
          if (frame_number == image_array.length) {
             if (hold > 1) {
                hold--;
                frame_number--;
             }
             else {
                if (cycle == 0) {
                   hold = pole;
          	    }
                frame_number = 0;
             }
          }
       }
    }
    One working example is at: http://air.ccny.cuny.edu/ws/geon/ani...ani0&channel=4
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    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 ...

    [CODE=javascript]var interval_id = window.setInter val("next_frame ()",interval_de lay);
    [/CODE]
    is equivalent to:

    [CODE=javascript]var interval_id = window.setInter val(next_frame, interval_delay) ;
    [/CODE]
    the first param is a function-reference that just could be passed by its name.

    kind regards

    Comment

    • strangeplant
      New Member
      • Jul 2008
      • 2

      #3
      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.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        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

        Comment

        Working...