Created
November 13, 2012 19:36
-
-
Save giuliandrimba/4067872 to your computer and use it in GitHub Desktop.
JavaScript: Load all images inside element
This file contains 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
(function($) | |
{ | |
/* | |
* Author: Giulian Drimba | |
* | |
*/ | |
$.fn.loadImages = function(callback, scope) | |
{ | |
var images = $(this).find("img"); | |
var totalImages = images.length; | |
var imagesLoaded = 0; | |
var self = this; | |
if(scope) | |
self = scope; | |
$(this).find("img").each(function() | |
{ | |
if ($(this).height() > 0) | |
{ | |
onLoadImage(); | |
} | |
else | |
{ | |
$(this).load(function() | |
{ | |
onLoadImage(); | |
}); | |
} | |
}); | |
function onLoadImage() | |
{ | |
imagesLoaded++; | |
if(imagesLoaded >= totalImages) | |
{ | |
if(callback) | |
callback.call(self,callback); | |
} | |
} | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment