javascript順序載入圖片的方法,javascript順序載入

來源:互聯網
上載者:User

javascript順序載入圖片的方法,javascript順序載入

本文執行個體講述了javascript順序載入圖片的方法。分享給大家供大家參考。具體如下:

javascript監聽一個圖片是否載入完畢 如果載入完成再載入下一張,不是一次性從伺服器載入 減少伺服器壓力,
可用到的地方:比如製作類似google地圖的應用,可以使小圖一張一張的載入

function Load_pic(arr){ this.loop_f=function(i,o_file,len,f,obj){   if(i<len-1){     i=i+1;     f(i,o_file,len,obj);     }  };  this.creat_pic=function(i,o_file,len,obj){    var f=arguments.callee,    doc=document,    image = doc.createElement("img");      image.src =o_file[i];    i<len?doc.getElementsByTagName("body")[0].appendChild(image):'';    if(navigator.userAgent.indexOf("MSIE")>0){         if($.browser.version==6.0 || $.browser.version==9.0){        //IE9和IE6一樣 微軟真是怪異          image.onreadystatechange = function () {             if (image.readyState == "complete"){               obj.loop_f(i,o_file,len,f,obj);            }           };         }else{           ie7imagetime = window.setInterval(function(){             var rs = image.readyState;             if(rs=="complete"){               window.clearInterval(ie7imagetime);               obj.loop_f(i,o_file,len,f,obj);            }else{               return;             }           },200);         }       }else{         image.onload = function () {           if (image.complete == true){           obj.loop_f(i,o_file,len,f,obj);          }         };     }  };    if(arr.constructor===Array){   var len=arr.length,      i=0;   i<len?this.creat_pic(i,arr,len,this):'';  }; }//調用方法new Load_pic(['http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/0_0.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/0_1.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/0_2.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/0_3.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/1_0.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/1_1.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/1_2.gif','http://gomap.dashilan.cn/jquery-mobile/map/cq/1/img_1/1_3.gif']);//注意要調用jquery 用於判斷瀏覽器

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.