Home > front-end development > Animated GIF not animating?

Animated GIF not animating?

February 4th, 2007

So it turns out that if you set up a loading spinner like this:

<div id="spinner" style="display: none"><img src="loading.gif"/>Loading...</div>

And then show the div, the animated gif will not animate in… which browser? IE6, of course.

Solutions:

Refresh the innerHTML content (This is stupid but it works..):

document.getElementById('spinner').style.display = '';  // show it, and then...
document.getElementById('spinner').innerHTML = document.getElementById('spinner').innerHTML;

OR
Set the animated gif as the div’s css background image instead of using the child IMG element. Perhaps:

#spinner { 
  background: url(loading.gif) no-repeat 5px 3px; 
  padding-left: 20px; }

The second solution is a little classier and is also better from a semantic POV, IMHO.

front-end development

  1. Euro
    October 13th, 2011 at 03:56 #1

    Cheers. Worked nicely.

  2. November 8th, 2011 at 07:45 #2

    Heh lol@lastreply, four years later, we're still supporting ie6. Almost people.. almost..

  3. November 16th, 2011 at 23:23 #3

    Great, it work :) .. many thanks

  1. No trackbacks yet.

For code blocks, use <pre lang="javascript">. css and html4strict are also accepted.