If you’ve noticed a gif image not animating properly in IE, then you are subject to another Internet Explorer bug. Surprise, surprise.
I was trying to use a loader animated gif in a form to show that a file was uploading. I put the image in a div with display: none in the style attribute. Then, when the user clicked the Submit button, it would change the div’s display to block. But in IE, when the div would appear with the gif image inside, the animated image would not play…it would simply be frozen in place. Here’s a sample of the code I was using:
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="myfile" />
<div id="loader_box" style="display: none;">
<img id="loader" src="images/loader.gif" />
</div>
<input type="submit" name="save" value="Add File" onclick="document.getElementById('loader_box').style.display='block';" />
</form>
I did my normal routine of Googling for the answer and finally found it. IE seems to get overwhelmed when it starts sending information, so it doesn’t allow the animation to play. But if you reload the image’s source after a setTimeout(), it restarts the animation and allows it to play.
Here’s how I fixed the problem:
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="myfile" />
<div id="loader_box" style="display: none;">
<img id="loader" src="images/loader.gif" />
</div>
<input type="submit" name="save" value="Add File" onclick="document.getElementById('loader_box').style.display='block'; setTimeout('document.getElementById(\'loader\').src=\'images/loader.gif\'', 500)" />
</form>
This fixed the problem! Why, oh why, dost thou torture our souls, oh great IE gods??
Uncategorized animated gifs, block, display, form, frames, ie, IE6, ie7, ie8, internet explorer, loader gif, loader image, none, not playing, onclick, stop animation, submit, upload file

Loading ...
Recent Comments