Skip to content

Instantly share code, notes, and snippets.

@devinsays
Created March 18, 2013 04:50
Show Gist options
  • Save devinsays/5185162 to your computer and use it in GitHub Desktop.
Save devinsays/5185162 to your computer and use it in GitHub Desktop.
jQuery Plugin for post loading images
// jQuery Plugin for post loading images
$.fn.postLoadImages = function(callback) {
var imgLen = this.length,
count = 0;
return this.each(function(count) {
count++;
if ($(this).attr('data-src')) {
var imgTag = this, imgSrc = $(this).attr('data-src');
i = new Image();
i.onload = function() {
$(imgTag).fadeTo(0,0).attr('src',imgSrc).fadeTo(400,1,function() {
if (imgLen == count) {
if (typeof callback == 'function') {
callback.call(this);
}
}
});
};
i.src = imgSrc;
}
});
};
@amazingBytes
Copy link

What does it do exactly?
Where should it be located in the HTML-Source - in the head? Before any other JS is loaded, including JQuery?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment