看這個
fiddle
var click_counter = 0;
$("#rotate").click(function() {
if(click_counter < 4) {
click_counter++;
} else {
click_counter = 1
}
switch(click_counter) {
case 1:
$("#box1").html("3");
$("#box1").css("background-color","#999999");
$("#box2").html("1");
$("#box2").css("background-color","#ffffff");
$("#box3").html("4");
$("#box3").css("background-color","#666666");
$("#box4").html("2");
$("#box4").css("background-color","#cccccc");
break;
case 2:
$("#box1").html("2");
$("#box1").css("background-color","#cccccc");
$("#box2").html("4");
$("#box2").css("background-color","#666666");
$("#box3").html("1");
$("#box3").css("background-color","#ffffff");
$("#box4").html("3");
$("#box4").css("background-color","#999999");
break;
case 3:
$("#box1").html("4");
$("#box1").css("background-color","#666666");
$("#box2").html("3");
$("#box2").css("background-color","#999999");
$("#box3").html("2");
$("#box3").css("background-color","#cccccc");
$("#box4").html("1");
$("#box4").css("background-color","#ffffff");
break;
case 4:
$("#box1").html("1");
$("#box1").css("background-color","#ffffff");
$("#box2").html("2");
$("#box2").css("background-color","#cccccc");
$("#box3").html("3");
$("#box3").css("background-color","#999999");
$("#box4").html("4");
$("#box4").css("background-color","#666666");
break;
}
});
嘗試(http://api.jquery.com/animate/ && || http://www.w3schools.com/css/css3_transitions.asp) –
你不能在浮動狀態下動畫變化,你可能必須絕對定位它們。 [這是當你不這樣做時會發生的事情](http://jsfiddle.net/meD8y/1/) –