function preLoad(imgs,options) { //接收相关数据之后实现加载 this.imgs = (typeof imgs === 'string') ? [imgs] : imgs; this.opts = $.extend({},preLoad.default,options); if(this.order === 'ordered'){ this._ordered(); } else if(this.order === 'unordered'){ this._unordered(); }}preLoad.default = {//默认参数 order:'unordered', each:null,//每一张图片加载完毕后执行 all:null//所有图片加载完毕后执行}preLoad.prototype._ordered = function() { var opts = this.opts, imgs = this.imgs, len = imgs.length, count = 0; load(); function load() { var imgObj = new Image(); $(imgObj).on('load error', function(e) { opts.each && opts.each(count); if ( count >= len) {opts.all && opts.all();} //所有图片已经加载完毕 else load(); count++; }); imgObj.src = src; }}
添加回答
举报
0/150
提交
取消