View Full Version : Problem with setInterval in new versions of FF

07-08-2008, 01:52 PM
Hi, I am using setInterval to create animations, and things were running smoothly until the last two FF updates. Now, some of the images are skipped, often, but not always, every other one. It does work perfectly in IE, and I did not expect that at all. I have looked over the web info, and the mozilla page, but cannot find my error. Wondering is this is a new bug.....

The main functional code is this:
var frame_number = 0;
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) {
if (frame_number == image_array.length) {
if (hold > 1) {
else {
if (cycle == 0) {
hold = pole;
frame_number = 0;
All of the variables are globals. Does anyone see the problem?

07-08-2008, 02:09 PM
You haven't shown enough of the code to tell. What's fish? What's hold? It would be best though if you could link to your page and tell us the exact version of FF running under what OS that has this problem.

Please post a link to the page on your site that contains the problematic code so we can check it out.

07-08-2008, 02:17 PM
You can get to the page at: http://air.ccny.cuny.edu/ws/geon/aninmaster.php?cloud=ani0&channel=4

07-08-2008, 02:31 PM
You still haven't told us the exact version of FF or your OS. I'm using:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080623 Firefox/

under Windows XP, and see no problem. But, just from looking at the page, and from what I can surmise from your posted code, I would guess, as you are displaying images from a loading routine of some sort, that it has to do with the images not being ready (loaded) yet. You may think this is a preloading routine, but since the images only begin to load as the page is loading, it is simply a loading routine.

I can tell you that only IE (as far as I know) gives as accurate a response to the complete property of an image object as most programmers would like. If you re using this property in your loading routine, that could be a part of the 'problem'.

I can also tell you that low speed connections will likely have no luck whatsoever with that page, regardless of the browser used. In fact, any but the highest speed connections working at optimal bandwidth would be choppy, at best.

07-08-2008, 02:52 PM
Looking at the code some more, I see the complete property isn't used at all. So the script has no way of knowing if the images are ready. Further, in FF at least, it appears that a separate image load event is occurring sometimes, most likely here:

document.images["image_holder"].src = image_array[frame_number].src;

If this is due to (as I suspect) the browser's cache being full, there is nothing to be done about it other than increasing the browser's cache size on the user end - javascript cannot do that. But if the cache could hold that many bytes, it may just be that doing it this way causes a new loading event, whereas if your image array were an array of DOM level 2 created image tags, and instead of swapping source attributes, you replaced the displaying tag, that might work out.

07-08-2008, 05:31 PM
I'm quite sure that it has nothing to do with browser cache size, since it works in IE and used to work flawlessly in FF until two updates ago, and since I can increase cache size without any gain.

Not sure that changing to switching image tags would be any benefit either since the image still has to be loaded. To me, it is a problem with setInterval. Try this link and you will see that I'm not the only one that sees this issue: http://pages.mckoss.com/setIntervalTest.htm

07-16-2008, 02:37 PM
Just to finish this thread, FF version 3.0 seems to have completely fixed this issue, and animations run smoothly with uniform and perfect timing. Today's update of FF 2.0.16 improves the timing quite significantly over 2.0.14/15 but not as good as FF 3.0 So, I'm leaving my animation code alone.