Created
January 23, 2013 21:24
-
-
Save amclean/4613608 to your computer and use it in GitHub Desktop.
The right way to preload images that allows for onload event firing even if IE has cached image.
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 imageLoadEvent = function(){ | |
console.log('image ready'); | |
} | |
var $newImg = this.$(new Image()), | |
src = 'blah.png'; | |
// using onreadstatechange to deal with cached stuff in IE | |
$newImg.bind('load readystatechange', function(e){ | |
if(this.complete || (this.readyState == 'complete' && e.type == 'readystatechange')) imageLoadEvent(); | |
}); | |
$newImg.attr('src', src); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment