Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@amazingBytes amazingBytes commented Mar 26, 2013

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