Sunday, December 25, 2011

continuously change the background color by using loop


Example :  continuously change the background color by using loop

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Background effect by using loop </title>


<script language="javascript">

var COLOR = 999999
var woot = 0
function stoploop() {
document.bgColor = '#fff';
clearTimeout(loopID);
}
function loopBackground() {
if (COLOR > 0) {
document.bgColor = '#' + COLOR
COLOR -= 111111
loopID = setTimeout("loopBackground()",1)
} else {
document.bgColor = '#000000'
woot += 10
COLOR = 999999
COLOR -= woot
loopID = setTimeout("loopBackground()",1)
   }
}
</script>
</head>

<body style="width:800px; margin:0 auto">
<center>
<h3> continuously change the background color by using loop </h3>


<FORM NAME="background">
<INPUT TYPE="button" VALUE="Start bgColor WARP"
onClick="loopBackground()">
<br>
<input type="button" value="Stop bgColor WARP" onClick="stoploop()">
</FORM>


</center>
</body>
</html>

2 comments: