Home | All Questions | alt.html FAQ > Client-side Basic Scripting

Is there a script that can cycle through a set of images on a page?

<script type="text/javascript">

 food = new Array
("applepie.gif","breadsticks.gif",
"burger.jpg","chickenfries.jpg",
"fajitas.jpg","kabobs.jpg",
"pizza.jpg","soupsalad.jpg",
"sub.gif","salad.jpg")

i=0
function rotateFood() {
if(i<food.length) {
document.mybanner.src=food[i]; i++
}

//this resets sequence of array items
//if it's messed up
else {
document.mybanner.src=food[0]
i=1
}

setTimeout("rotateFood()",1500)
}
</script>
</head>

<body onLoad="rotateFood()">


<!-- must write starting image to run function -->

<img src="applepie.gif" name="mybanner"><p>

Recommended Resources

Discussion

Related Questions