Created
March 18, 2013 04:50
-
-
Save devinsays/5185162 to your computer and use it in GitHub Desktop.
jQuery Plugin for post loading images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?