View Full Version : interval along with span + a repeat :)
mattover-matter
04-12-2003, 04:56 AM
Hi, How can I make a function that loops through a certain number of times and changes a color from an array?
var color[1] = "00ff00"
var color[2] = "0000ff"
etc.
then like
function changecolor(){
for (i=0;i++;color.length;){
spanname.style.color=color[i]
}
}
set interval(changecolor, 2000)
or whatknot.
Thanks all
HairyTeeth
04-12-2003, 07:15 AM
try this for a lark:
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
#box {
position:absolute;
visibility:visible;
top:50px;
left:300px;
width:100px;
height:50px;
border:solid 1px #EEEEEE;
color:#FFFFFF;
}
-->
</style>
<script type="text/javascript" language="javascript">
<!--;
var theArray = new Array('006600','339933','ff0044','994466','6611ff')
var i = 0;
function foo(){
i++
if(i == theArray.length) i = 0;
document.getElementById('box').style.backgroundColor=theArray[i];
setTimeout("foo()",500);
}
//-->
</script>
</head>
<body>
<a href="javascript: foo()">Set It Off!!</a>
<div id="box" style="text-align:center;">
WOW!
</div>
</body>
</html>
mattover-matter
04-12-2003, 03:50 PM
any reason for the ending on "thearray" to be on the next line?
also, what is "foo"?
thanks, I will use that
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.