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