Created
October 19, 2012 15:40
-
-
Save btleffler/3918927 to your computer and use it in GitHub Desktop.
Make sure images are loaded with the "load" event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var img = jQuery("<img>") | |
.attr("src", "img.png") | |
.bind("load", function () { | |
var interval = setInterval(function () { | |
if (img[0].complete) { | |
doTheRestOfYourStuffThatUsesThisImgButDontForgetToClearThisInterval(); | |
} | |
}, 100); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
load
event works, except in IE. IE fires theload
event before the image is loaded, so you have to do this janky stuff to make sure it's actually loaded.