var i = 2; //Assumes drawing1 is already applied to the div
var nextDrawing = function(){
$("div").removeClass()
.addClass("drawing"+i);
i = ((i + 1) % 5); //To cycle from 1 to 5
i = i == 0 ? 5 : i;
}
$('#start').click(function(){
setInterval(nextDrawing, 500);
});
应该做的伎俩。
编辑:如果有人多次单击按钮,则以下修改可能对清除间隔有用。
var i = 2; //Assumes drawing1 is already applied to the div
var nextDrawing = function(){
$("div").removeClass()
.addClass("drawing"+i);
i = ((i + 1) % 5); //To cycle from 1 to 5
i = i == 0 ? 5 : i;
}
var intervalID = undefined;
$('#start').click(function(){
if( intervalID != undefined )
{
clearInterval(intervalID);
}
intervalID = setInterval(nextDrawing, 500);
});
这是一个工作示例:http: //jsfiddle.net/ajhuU/