First, judge the browser and determine whether the image is loaded. If the image is not loaded yet, "loading..." is displayed. The idea and Code are as follows:
Image pre-loadingScript // judge the Browser var Browser = new Object (); Browser. userAgent = window. navigator. userAgent. toLowerCase (); Browser. ie =/msie /. test (Browser. userAgent); Browser. moz =/gecko /. test (Browser. userAgent); // determine whether the function Imagess (url, imgid, callback) {var val = url; var img = new Image (); if (Browser. ie) {img. onreadystatechange = function () {if (img. readyState = "complete" | img. readyState = "loaded") {callback (img, imgid) ;}} else if (Browser. moz) {img. onload = function () {if (img. complete = true) {callback (img, imgid) ;}}// if an exception occurs due to a network or image, the image img is displayed. onerror = function () {img. src =' http://www.baidu.com/img/baidu_logo.gif '} Img. src = val;} // display the image function checkimg (obj, imgid) {document. getElementById (imgid ). src = obj. src;} // initialize the image to be displayed and specify the display position window. onload = function () {Imagess (" http://hiphotos.baidu.com/lovebyakuya/pic/item/01cf20088f9506f063d98653.jpg "," Img1 ", checkimg); Imagess (" http://hiphotos.baidu.com/lovebyakuya/pic/item/7b7b19c70d62f4fdd0006050.jpg "," Img2 ", checkimg); Imagess (" http://hiphotos.baidu.com/joanne728/pic/item/892557641806d20eaa184c71.jpg "," Img3 ", checkimg); Imagess (" http://www.neocha.com/-/res/Camilla/20071204181216078845_h.jpg "," Img4 ", checkimg); Imagess (" http://www.neocha.com/-/res/Camilla/20071204181216d078845_h . "," Img5 ", checkimg);} script