Image loading is slow, which leads to poor user experience. This article introduces an image pre-loading technology. For more information, see
The Code is as follows:
Js implements the action after the image is pre-loaded.
Script
Var I = 0;
Var c = 3;
Var imgarr = new Array
Imgarr [0] = "http://www.baidu.com/img/baidu_logo.gif ";
Imgarr [1] = "http://img.baidu.com/img/logo-img.gif ";
Imgarr [2] = "http://img.baidu.com/img/logo-zhidao.gif ";
Var Browser = new Object ();
Browser. userAgent = window. navigator. userAgent. toLowerCase ();
Browser. ie =/msie/. test (Browser. userAgent );
Browser. Moz =/gecko/. test (Browser. userAgent );
Function SImage (url, callback)
{
Var img = new Image ();
If (Browser. ie ){
Img. onreadystatechange = function (){
If (img. readyState = "complete" | img. readyState = "loaded "){
Ii = I + 1;
Callback (I );
}
}
} Else if (Browser. Moz ){
Img. onload = function (){
If (img. complete = true ){
Ii = I + 1;
Callback (I );
}
}
}
Img. src = url;
}
Function icall (v)
{
If (v SImage ("" + imgarr [v] + "", icall );
}
Else if (v> = c ){
I = 0;
// Location.replace('banner.html '); // write your own actions here,
}
}