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; ? ?}}
我是那出問題了?為什么有序加載只能加載第一個
qq_nn_19
2017-10-26 17:52:29