Java代碼
var Imgvalue;
var Count =13; //圖片數(shù)量
var Imgs = new Array(Count);
var ImgLoaded =0;
//預(yù)加載圖片
function preLoadImgs()
{
alert('圖片加載中請(qǐng)稍等......');
for(var i=0;i<Imgs.length;i++){
Imgs[i]=new Image();
downloadImage(i);
}
}
//加載單個(gè)圖片
function downloadImage(i)
{
var imageIndex = i+1; //圖片以1開始
Imgs[i].src = "images/"+imageIndex+".jpg";
Imgs[i].onLoad=validateImages(i);
}
//驗(yàn)證是否成功加載完成,如不成功則重新加載
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('圖片加載完畢!');
}
}
}
//開始
function RandStart()
{
Init = setInterval('SetRand()',50);
}
//隨機(jī)顯示
function SetRand()
{
imageIndex = Math.floor(Math.random()*Count);
document.getElementById("ImgView").src = Imgs[imageIndex].src;
}
//結(jié)束
function RandStop()
{
window.clearInterval(Init);
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。