JS Picture buffer Loading code instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.