Skip to content

Instantly share code, notes, and snippets.

@PoTHuYJoHN
Created July 24, 2013 08:56
Show Gist options
  • Save PoTHuYJoHN/6069012 to your computer and use it in GitHub Desktop.
Save PoTHuYJoHN/6069012 to your computer and use it in GitHub Desktop.
Image preloader
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);
});
}
});
}
}
}
@PoTHuYJoHN
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment