Home >Web Front-end >JS Tutorial >又一个小巧的图片预加载类_图象特效

又一个小巧的图片预加载类_图象特效

WBOY
WBOYOriginal
2016-05-16 19:13:571246browse
复制代码 代码如下:

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


 New Document 

<script> <BR><!-- <BR>var IE=navigator.appName=="Microsoft Internet Explorer"; <BR>var Opera=navigator.appName.toLowerCase()=="opera"; <BR>var FF=!IE && !Opera; <BR>function LoadImage(arrSrc,callBack) <BR>{ <BR> this.Length=arrSrc.length; <BR> this.LoadedLen=0; //已经被加载的图片个数 <BR> var self=this; <BR> if(self.Length<1) <BR> { <BR> callBack(arrSrc); <BR> return; <BR> } <br><br> //经测试,OPERA与别的浏览器加载方式不同,所以特别独立开来... <BR> if(Opera) <BR> { <BR> for(var i=0;i<self.Length;i++) <BR> { <BR> var tmpImg=new Image(); <BR> tmpImg.src=arrSrc[i]; <BR> tmpImg.onload=function() <BR> { <BR> self.LoadedLen++; <BR> if(self.LoadedLen==self.Length && callBack) callBack(arrSrc); <BR> } <BR> } <BR> return; <BR> } <br><br> this.Load=function() <BR> { <BR> self.LoadedLen++; <BR> document.getElementById("counter").innerHTML=self.LoadedLen; <BR> if(self.LoadedLen<self.Length) self.DownImg(); <BR> else if(callBack) callBack(arrSrc); <BR> } <br><br> this.DownImg=function() <BR> { <BR> var tmpImg=new Image(); <BR> tmpImg.src=arrSrc[self.LoadedLen]; <BR> if(IE) <BR> { <BR> if(tmpImg.readyState=="complete") self.Load(); <BR> else tmpImg.onreadystatechange=function() <BR> { <BR> if(this.readyState=="complete") self.Load(); <BR> } <BR> } <BR> else tmpImg.onload=self.Load; <BR> } <BR> this.DownImg(); <BR>} <BR>//--> <BR></script>



 <script> <BR> <!-- <BR> var arr=['http://photo.hjbbs.com/photo/20060531/20060531103027226_756_o.jpg','http://img1.soufun.com/bbs/2007_02/13/1171345302199.jpeg','http://img.c8c8.cn/2006/09/09/15032/pp20060909002749.jpg']; <BR> var t=new LoadImage(arr,function(arr) <BR> { <br><br> var str=""; <BR> for(var i=0;i<arr.length;i++) <BR> { <BR> str+="<img src='"+arr[i]+"' / alt="又一个小巧的图片预加载类_图象特效" ><br>"; <BR> } <BR> document.body.innerHTML+=str; <BR> }); <BR> //--> <BR> </script>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn