我想每隔60秒执行一个不同的动作,通过动画来改变我的背景。现在单击即可运行。
$(document).ready(function(){
$("li.one").click( function(){
$('#switch-container').animate({backgroundColor: '#18597f'}, 1000)
});
$("li.two").click( function(){
$('#switch-container').animate({backgroundColor: '#8a0651'}, 1000)
});
$("li.three").click( function(){
$('#switch-container').animate({backgroundColor: '#8a0651'}, 1000)
});我怎么能这样做呢?谢谢!
发布于 2013-03-20 16:12:24
var colors = ['#18597f','#8a0651','#8a0651'],
timer = setInterval(function() {
var rand = parseInt(Math.random()*(3 - 0),10);
$('#switch-container').animate({backgroundColor: colors[rand]}, 1000);
}, 1000);编辑:
要按常规顺序而不是随机更改颜色,请执行以下操作:
var colors = ['green','red','yellow'],
i = 0,
timer = setInterval(function() {
$('#switch-container').animate({backgroundColor: colors[i++]}, 500);
i = i==3 ? 0 : i;
}, 1000);https://stackoverflow.com/questions/15518240
复制相似问题