Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created January 21, 2011 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobstel/789615 to your computer and use it in GitHub Desktop.
Save sobstel/789615 to your computer and use it in GitHub Desktop.
jQuery onload event for images
jQuery.fn.whenLoaded = function(fn){
return this.each(function(){
// if already loaded call callback
if (this.complete || this.readyState == 'complete'){
fn.call(this);
} else { // otherwise bind onload event
$(this).load(fn);
}
});
}
$('img').whenLoaded(function(){
console.log(this.src + ' loaded');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment