Using setInterval () to Repeatedly Change the Document Background Color
<HTML>
<HEAD>
<TITLE>Using setInterval()</TITLE>
<SCRIPT LANGUAGE="JavaScript1.2"><!--
colors = new Array("red","orange","green","blue","brown","purple","gray","white")
colorIndex = 0
function changeColor() {
document.bgColor = colors[colorIndex]
colorIndex = (colorIndex + 1) % colors.length
}
function startColorChange() {
setInterval("changeColor()",3000)
}
window.onload = startColorChange
// --></SCRIPT>
</HEAD>
<BODY BGCOLOR="white">
<P>The setInterval() repeatedly changes the
document background color every three seconds.</P>
</BODY>
</HTML>
Related examples in the same category