Java code
Var Imgvalue;
Var Count = 13; // number of images
Var Imgs = new Array (Count );
Var ImgLoaded = 0;
// Pre-load the image
Function preLoadImgs ()
{
Alert ('wait a moment before loading the image ......');
For (var I = 0; I Imgs [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 the loading fails, reload the file.
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 );
}
This article is from "struggling birds"