一:引入ImgPreloader.js
(function() {
function Preloader(srcs, opts) {
this.srcs = srcs;
this.opts = opts ||{};
this.loaded = [];
this.load();
}
Preloader.prototype.load = function() {
for (var i = 0; i < this.srcs.length; ++i) {
var src = this.srcs[i];
this.loadImg(src);
}
};
Preloader.prototype.loadImg = function(src) {
var that = this;
var img = new Image();
img.onload = function() {
that.onload(img);
};
img.src = src;
};
Preloader.prototype.onload = function(obj) {
this.loaded.push(obj);
if (this.opts.each instanceof Function) {
var percent = this.loaded.length / this.srcs.length;
this.o