-
-
Save crazy4groovy/2370716 to your computer and use it in GitHub Desktop.
jQuery images loaded function
This file contains hidden or 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
/* | |
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