Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Forked from Mottie/gist:1491097
Created April 12, 2012 20:19
Show Gist options
  • Save crazy4groovy/2370716 to your computer and use it in GitHub Desktop.
Save crazy4groovy/2370716 to your computer and use it in GitHub Desktop.
jQuery images loaded function
/*
Check if all images are loaded
- Callback occurs when all images are loaded
- image load errors are ignored (complete will be true)
- Use:
$('.wrap img').imagesLoaded(function(){
alert('all images loaded');
});
*/
jQuery.fn.extend({
imagesLoaded: function( callback ) {
var i, c = true, t = this, l = t.length;
for ( i = 0; i < l; i++ ) {
if (this[i].tagName === "IMG") {
c = (c && this[i].complete && this[i].height !== 0);
}
}
if (c) {
if (typeof callback === "function") { callback(); }
} else {
setTimeout(function(){
jQuery(t).imagesLoaded( callback );
}, 200);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment