var imgObj = new Image();
$(imgObj).on('load error',function () {
opts.each && opts.each(count); //检查参数是否存在
if (count >= len - 1){
opts.all && opts.all();
}
count++;
});
imgObj.src = src;
function load() {
var imgObj = new Image();
$(imgObj).on('load, error', function () {
opts.each && opts.each(count);
if(count >= len){
//所有图片加载完成
opts.all && opts.all();
} else {
load();
}
count++;
});
imgObj.src = imgs[count];插件源码中each和all的默认值都是null,所以调用preload()的时候需要传递这两个方法进去,