0
我的目標是在加載實際圖像時進行圖像預加載,但我無法弄清楚。整個目標是我有一個幻燈片顯示圖像,但有時它加載緩慢..大聲笑。這裏是我的HTML:圖片預加載javascript
<div id="slideshow">
<img src="../images/slideshow/spacer.gif" width="100" height="100" id="myPicture" alt="some image">
</div>
這裏是我的javascript我已經:
window.onload = choosePic;
function choosePic() {
var myPix = new Array("../images/slideshow/sempiternal.png", "../images/slideshow/cross.png", "../images/slideshow/pentagram.png");
var randomNum = Math.floor((Math.random() * myPix.length));
document.getElementById("myPicture").src = myPix[randomNum];
}
而CSS:
#slideshow {
height: 100px;
width: 100px;
position: fixed;
bottom: 20px;
right: 20px;
}
這就是我的想法,但我想看看是否有其他人可以想到的東西。謝謝你的時間! –