JSFiddle - React, Tailwind, and code Playground
HTML
<img src="http://www.cirkuit.net/projects/jquery/onImagesLoad/images/4.jpg" caption='img 1'>
<img src="http://www.cirkuit.net/projects/jquery/onImagesLoad/images/9.jpg" caption='img 2'>
<div id="loaded"></div>
JavaScript
(function($){
$.fn.onImagesLoad = function(options){
var self = this;
self.opts = $.extend({}, $.fn.onImagesLoad.defaults, options);
self.bindEvents = function($imgs, container, callback){
if ($imgs.length === 0){ //no images were in selection. callback based on options
if (self.opts.callbackIfNoImagesExist && callback){ callback(container); }
}
else {
var loadedImages = [];
if (!$imgs.jquery){ $imgs = $($imgs); }
$imgs.each(function(i){
//webkit fix inspiration thanks to bmsterling: http://plugins.jquery.com/node/10312
var orgSrc = this.src;
if (!$.browser.msie) {
this.src = ""; //ie will do funky things if this is here (show the image as an X, only show half of the image, etc)
}
$(this).bind('load', function(){
if (jQuery.inArray(i, loadedImages) < 0){ //don't double count images
loadedImages.push(i); //keep a record of images we've seen
if (loadedImages.length == $imgs.length){
if (callback){ callback.call(container, container); }
}
}
});
if (!$.browser.msie) {
this.src = orgSrc; //needed for potential cached images
}
else if (this.complete || this.complete === undefined){ this.src = orgSrc; }
});
}
};
var imgAry = []; //only used if self.opts.selectorCallback exists
self.each(function(){
if (self.opts.itemCallback){
var $imgs;
if (this.tagName == "IMG"){ $imgs = this; } //is an image
else { $imgs = $('img', this); } //contains image(s)
...