JS Picture Buffer Loading code example:
General pictures or pictures of more sites will use the picture buffer loading technology, can be said to improve the experience of the site has a good effect, the following share a network of relevant code, I hope to bring you some help, the code is as follows:
<Scripttype= "Text/javascript"> varImgvalue;varCount= -;//Number of picturesvarIMGs= NewArray (Count);varimgloaded=0; //pre-load picturefunctionPreloadimgs () {alert ('Please wait while the picture is loaded ...'); for(varI=0; I<Imgs.length;i++) {Imgs[i]=NewImage (); Downloadimage (i); } } //load a single picturefunctionDownloadimage (i) {varImageIndex=I+1; //Pictures starting with 1imgs[i].src= "images/"+ImageIndex+". jpg"; Imgs[i].onload=validateimages (i);} //Verify that the load completes successfully, and reload if unsuccessfulfunctionValidateimages (i) {if(!imgs[i].complete) {Window.settimeout ('Downloadimage ('+I+')', $); } Else if(typeofImgs[i].naturalwidth!="undefined"&&Imgs[i].naturalwidth==0) {window.settimeout ('Downloadimage ('+I+')', $); } Else{imgloaded++ if(imgloaded==Count) {document.getElementById ('btnstart'). Disabled=false; document.getElementById ('Btnstop'). Disabled=false; Alert ('Picture loading complete! '); } } } //StartfunctionRandstart () {Init=SetInterval ('Setrand ()', -); } //Random DisplayfunctionSetrand () {ImageIndex=Math.floor (Math.random ()*Count); document.getElementById ("Imgview"). SRC=imgs[imageindex].src;} //EndfunctionRandstop () {window.clearinterval (Init);}</Script>
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8848
For more information, refer to: http://www.softwhy.com/javascript/
JS Picture buffer Loading code instance