Skip to content

Instantly share code, notes, and snippets.

@robv
Created November 4, 2010 19:24
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 robv/663023 to your computer and use it in GitHub Desktop.
Save robv/663023 to your computer and use it in GitHub Desktop.
$(function() {
$.fn.imagesLoaded = function(callback){
var elems = this.filter('img'),
len = elems.length;
elems.bind('load',function(){
if (--len <= 0){ callback.call(elems,this); }
}).each(function(){
// cached images don't fire load sometimes, so we reset src.
if (this.complete || this.complete === undefined){
var src = this.src;
// webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
// data uri bypasses webkit log warning (thx doug jones)
this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
this.src = src;
}
});
return this;
};
$('#image').hide();
$('#loader').show();
$('#image').imagesLoaded(function(){
$(this).show();
$('#loader').hide();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment