我正在尝试通过超时更改文本的颜色。就像每5秒颜色应该改变一次。我只是无法让它工作。我究竟做错了什么?
var rainBowColors = new Array();
rainBowColors.push("#FF0000"); //Red: #FF0000
rainBowColors.push("#FF7F00"); //Orange: #FF7F00
rainBowColors.push("#FFFF00"); //Yellow: #FFFF00
rainBowColors.push("#00FF00"); //Green: #00FF00
rainBowColors.push("#0000FF"); //Blue: #0000FF
rainBowColors.push("#4B0082"); //Indigo: #4B0082
rainBowColors.push("#8F00FF"); //Violet: #8F00FF
var rainbowCounter = 0;
for (var counter = 0; counter < 1000; counter++)
{
//Easter :)
//var timeOut = setTimeOut(function(){
jQuery(".text").css("color", rainBowColors[rainbowCounter]);
//}, 500);
//clearTimeOut(timeOut);
//Higher Counter
rainbowCounter++;
//Reset counter
if (rainbowCounter == rainBowColors.length)
{
rainbowCounter = 0;
}
}
完整示例:http: //jsfiddle.net/xLS25/