我有6個「塊」,而且每個包含不同的文本,爲簡單起見,我們只考慮這些作爲我的「塊」如何在每次點擊時都反轉動畫?
<div id="block1"> <h2> Block1 </h2> </div
我對他們有3可見和3隱藏。我有一個按鈕,取代相應的塊
$(".showmore").click(function(){
$("#block1").fadeOut("slow", function(){
$(this).replaceWith($("#block4").html());
$(this).fadeIn("slow");
});
$("#block2").delay(400).fadeOut("slow", function(){
$(this).replaceWith($("#block5").html());
$(this).fadeIn("slow");
});
$("#block3").delay(800).fadeOut("slow", function(){
$(this).replaceWith($("#block6").html());
$(this).fadeIn("slow");
});
$(this).text('Show less');
});
它工作正常,但不知道如何恢復它。我試圖將元素克隆到一個變量,然後加載它們,但似乎id已經消失,因爲當我試圖隱藏block1或block4時,它們都沒有消失。誰能幫忙?
請添加更多HTML代碼,或者在jsfiddle上提供代碼 –
相關http://stackoverflow.com/questions/2132090/jquery-reversing-animation-on-second-click http://stackoverflow.com/questions/ 27166633 /第二次點擊反向動畫 – yuriy636