Skip to content

Instantly share code, notes, and snippets.

@btleffler
Created October 19, 2012 15:40
Show Gist options
  • Save btleffler/3918927 to your computer and use it in GitHub Desktop.
Save btleffler/3918927 to your computer and use it in GitHub Desktop.
Make sure images are loaded with the "load" event
var img = jQuery("<img>")
.attr("src", "img.png")
.bind("load", function () {
var interval = setInterval(function () {
if (img[0].complete) {
doTheRestOfYourStuffThatUsesThisImgButDontForgetToClearThisInterval();
}
}, 100);
});
@btleffler
Copy link
Author

The load event works, except in IE. IE fires the load event before the image is loaded, so you have to do this janky stuff to make sure it's actually loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment