Created
July 24, 2013 08:56
-
-
Save PoTHuYJoHN/6069012 to your computer and use it in GitHub Desktop.
Image preloader
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
var imgs = { | |
$wrap : false, | |
$imgs : false, | |
settings : { | |
beforeClass : 'preload', | |
triggerClass : 'visible', | |
excludeClass : '.no-preload' | |
}, | |
init : function() { | |
var set = imgs.settings; | |
this.$wrap = $('.content, .pbox-outer'); | |
this.$imgs = this.$wrap.find('img').not(set.excludeClass); | |
var len = this.$imgs.length; | |
if(len && s.isIe === false) { | |
this.$imgs.addClass(set.beforeClass); | |
this.$imgs.each(function() { | |
var $this = $(this); | |
if (this.complete) { | |
$this.addClass(set.triggerClass); | |
} else { | |
$this.load(function() { | |
$this.addClass(set.triggerClass); | |
}); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to use:
imgs.init();
You can set
"beforeClass"( class for all images which are preloading),
"triggerClass" (class added after loading),
"excludeClass" (image with with class won't be preloaded)