我想在背景颜色数组之间进行动画处理。jQuery动画背景颜色。删除Math.random
我发现下面的代码,但它使用Math.random以随机顺序显示背景颜色。
$(document).ready(function() {
setInterval(function() {
var theColours = Array('#ffffff','#000000','#00ff00','#ff0000','#0000ff');
var theColour = theColours[Math.floor(Math.random()*theColours.length)];
$('#branding').animate({backgroundColor: theColour}, 500);
}, 1000);
});
我想删除的Math.random和显示阵列中的下一个颜色。
但是,如果我使用以下代码替换Math.random,则动画不会超出数组中的第一个颜色。
$(document).ready(function() {
setInterval(function() {
var theColours = Array('#ffffff','#000000','#00ff00','#ff0000','#0000ff');
var currentColour = 0;
var theColour = theColours[Math.floor(currentColour++ % theColours.length)];
$('#branding').animate({backgroundColor: theColour}, 500);
}, 1000);
});