Home > Web Front-end > JS Tutorial > Example code of image buffer loading technology in JS_javascript skills

Example code of image buffer loading technology in JS_javascript skills

WBOY
Release: 2016-05-16 17:24:01
Original
1110 people have browsed it
Copy code The code is as follows:

var Imgvalue;
var Count =13; //Number of pictures
var Imgs = new Array(Count);
var ImgLoaded =0;
//Preload images
function preLoadImgs()
{
alert('Please wait while the image is loading Wait...');
for(var i=0;iImgs[i]=new Image();
downloadImage(i);
}
}
//Load a single image
function downloadImage(i)
{
var imageIndex = i 1; //The image starts with 1
Imgs[i] .src = "images/" imageIndex ".jpg";
Imgs[i].onLoad=validateImages(i);
}
//Verify whether the loading is successful, if not, reload
function validateImages(i){
if (!Imgs[i].complete)
{
window.setTimeout('downloadImage(' i ')',200);
}
else if (typeof Imgs[i].naturalWidth != "undefined" && Imgs[i].naturalWidth == 0)
{
window.setTimeout('downloadImage(' i ')',200);
}
else
{
ImgLoaded
if(ImgLoaded == Count)
{
document.getElementById('BtnStart'). disabled=false;
document .getElementById('BtnStop').disabled=false;
alert('Image loaded! ');
}
}
}
//Start
function RandStart()
{
Init = setInterval('SetRand()',50); >}
//Random display
function SetRand()
{
imageIndex = Math.floor(Math.random()*Count);
document.getElementById("ImgView"). src = Imgs[imageIndex].src;
}
//End
function RandStop()
{
window.clearInterval(Init);
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template