复制代码 代码如下: js 实现图片预加载 加载完后执行动作 <br><!-- <BR>*html{ <BR>margin:0; <BR>padding:0; <BR>border:0; <BR>} <BR>body{border:1px solid #f3f3f3; background:#fefefe} <BR>div#loading{ <BR>width:950px; <BR>height:265px; <BR>line-height:265px; <BR>overflow:hidden; <BR>position:relative; <BR>text-align:center; <BR>} <BR>div#loading p{ <BR>position:static; <BR> position:absolute; <BR>top:50%; <BR>vertical-align:middle; <BR>} <BR>div#loading p img{ <BR>position:static; <BR> position:relative; <BR>top:-50%;left:-50%; <BR>vertical-align:middle <BR>} <BR>--> <br> <br>var i=0; <br>var c=3; <br>var imgarr=new Array <br>imgarr[0]="http://www.baidu.com/img/baidu_logo.gif"; <br>imgarr[1]="http://img.baidu.com/img/logo-img.gif"; <br>imgarr[2]="http://img.baidu.com/img/logo-zhidao.gif"; <br>var Browser=new Object(); <br>Browser.userAgent=window.navigator.userAgent.toLowerCase(); <br>Browser.ie=/msie/.test(Browser.userAgent); <br>Browser.Moz=/gecko/.test(Browser.userAgent); <br>function SImage(url,callback) <br>{ <br>var img = new Image(); <br>if(Browser.ie){ <br>img.onreadystatechange =function(){ <br>if(img.readyState=="complete"||img.readyState=="loaded"){ <br>ii=i 1; <br>callback(i); <br>} <br>} <br>}else if(Browser.Moz){ <br>img.onload=function(){ <br>if(img.complete==true){ <br>ii=i 1; <br>callback(i); <br>} <br>} <br>} <br>img.src=url; <br><br>} <br><br>function icall(v) <br>{ <br>if(v<c){ <BR>SImage("" imgarr[v] "",icall); <BR>} <BR>else if(v>=c){ <br>i=0; <br>//location.replace('banner.html');//这里写自己的动作吧, <br>} <br>} <br> </div>