Preloading von Bildern mittels JavaScript


Dieser hier aufgeführte Code stamm von www.sietexperts.com

var imgArray = new Array("/gifs/insided.gif","/gifs/logo.gif","/gifs/cover.gif")
var iCnt = 0

function DoLoad() {
if (iCnt < imgArray.length) {
var loadImage = new Image
iCnt++
loadImage.onerror = loadImage.onload = DoLoad
loadImage.src = imgArray[iCnt-1]
} else
window.location.replace("NextPage.htm")
}

window.onload = DoLoad


Preloading mit Rollover Effekt

<SCRIPT>
var imgArray = new Array("/gifs/red.gif")
var iCnt = 0

function DoLoad() {
if (iCnt < imgArray.length) {
var loadImage = new Image
iCnt++
loadImage.onerror = loadImage.onload = DoLoad
loadImage.src = imgArray[iCnt-1]
} else
window.location.replace("NextPage.htm")
}

window.onload = DoLoad

function swapImage(sName,sImage) {
document.images[sName].src = sImage
}
</SCRIPT>
<A HREF="#"
ONCLICK="return false"
ONMOUSEOVER="swapImage('myImage','/gifs/red.gif')"
ONMOUSEOUT="swapImage('myImage','gifs/blue.gif')"
>
<IMG SRC='/gifs/blue.gif' NAME='myImage'>
</A>