Using setInterval () to Repeatedly Change the Document Background Color : Color « Development « JavaScript DHTML






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

1. Using Colors in JavaScript
2.Code for the Actual JavaScript Code and Color Selectors
3.Using Color Attributes: how document colors can be changed
4.Color Sampler