Internet Explorer just keeps amazing me (in a bad way). The latest surprise is an animated GIF that does not work.
I was using the following jQuery code:
$("body").append(
'<div id="throbber" style="display:none;"><img src="loading.gif"/></div>');
...
$("#throbber").show();
Internet Explorer shows the image but the animation does not work. Of course there is no problem in Firefox.
Based on the discussion here this is caused by the fact that the element was invisible when it was added to the DOM. Afterwards when you show the element IE does not start the animation.
As a workaround you can restructure your code and add the image to the DOM when it must be shown. That works in IE (and the other decent browsers).
$("body").append('<div id="throbber"><img src="animation.gif"/></div>');

17 Comments
Great hint, I've been stuck
Submitted by Markus on
Great hint, I've been stuck on this one for some time now, thanks for sharing!
Excellent observation. I
Submitted by Nate Williams on
Excellent observation. I wondered why my images weren't animating, and I had the same causes. I was un-hiding divs using jquery, and the image was not animating.
Thanks!
Thanks a lot! IE is really
Submitted by Anonymous on
Thanks a lot! IE is really amazingly buggy.
Interesting, albeit it works
Submitted by Michael Schøler on
Interesting, albeit it works just fine for me?
See my four different ajax spinner experiments here.
Best regards,
Michael Schøler
Denmark
Thank you for the tip. Any
Submitted by Anonymous on
Thank you for the tip.
Any way to make the animaged image work with standard html markup. I too have a hidden div and as others have posted that is causing the problem in IE. FF is ok too.
@Michael Schøler hello Can
Submitted by Anonymous on
@Michael Schøler
hello
Can you please confirm that if the animation works when you are submitting a page?
Say you are uploading a file. when you click upload, the spinner appears before the page gets submitted.
for me, in this case the animation do not work. works fine in FF
thanks
Yes it works for submitting
Submitted by Anonymous on
Yes it works for submitting a page.
still not animating
Submitted by Anonymous on
still not animating
Great post, this worked for
Submitted by Anonymous on
Great post, this worked for me.
doesn't work for me with IE
Submitted by Anonymous on
doesn't work for me with IE 6 and 7 at least.
thing is, it's animating fine, >>until<< the new page is beeing loaded. as soon as the loading of the new page starts, the GIF stops animating - where this is the only situation i need that animation, while a page is loading. *sigh*
currently have the showLoadingStuff() within an onunload event. dunno if this is a problem too. was just a quick hack and it does work for all other browsers i've tested.
is there a way to manualy trigger the animation?
onbeforeunload that event
Submitted by Anonymous on
onbeforeunload that event is, my sorrz
Thanks lot for your help...
Submitted by Anonymous on
Thanks lot for your help...
you should add .empty()
Submitted by Anonymous on
you should add .empty() before .append() as you will run the risk of adding multiple spinners to the container
Thank you very much for
Submitted by Tom Regan on
Thank you very much for posting that solution.
Thanks a lot for the
Submitted by Naresh on
Thanks a lot for the solution.
I have tried
Submitted by Vinod kumar on
I have tried this
document.getElementById("myElement").innerHTML = "";
and its work perfect for me.
The problem with animated
Submitted by Lars Hemel on
The problem with animated gifs in IE is that they have to be added to the DOM when they are visible, otherwise they are not rendered as such. See http://www.larshemel.com/forum/animated_gif_problems_ie for detailed info.
So, it actually is plain simple. Add the code at the moment you want it to be displayed.