2015-01-16 22 views
0

我使用jQuery動畫來爲某些div創建動畫。我有什麼辦法清除動畫第二格之前完成第一個div的所有更改?在開始新動畫之前清除所有使用jquery動畫完成的更改

 $(".order-b").click(function(event){ 
     $(".order-t").animate({top:'30%'}, "slow"); 
     }); 

     $(".counsel-b").click(function(){ 
     $(".counsel-t").animate({top:'30%'}, "slow"); 
     }); 


<div class="process-bars"> 
    <!-- first DIV --> 
    <div class="order-b"> 
     <div class="order-t"> 
      <i class="fa fa-shopping-cart"></i> 
      <h1>Order</h1> 
     </div>          
    </div> 

    <!-- Second DIV --> 
    <div class="counsel-b"> 
     <div class="counsel-t"> 
      <i class="fa fa-shopping-cart"></i> 
      <h1>Order</h1> 
     </div>           
    </div> 
</div> 

CSS代碼:

.order-t, counsel-t { 
position:absolute; 
top:52%; 
width: 100%; 
margin:0 auto; 
z-index:2; 

}

我要清除的第一個div的動畫,當我點擊第二個div。 我該怎麼做?!我不想做像下面的代碼:這個答案顯示

 $(".order-b").click(function(event){ 
     $(".order-t").animate({top:'30%'}, "slow"); 
     $(".counsel-t").animate({top:'52%'}, "slow"); 
     }); 
+0

你可以在小提琴或其他東西中重現這個嗎?這將有助於有你的CSS和'.counsel-t'在你的HTML? – jmore009

+0

我編輯了代碼。有一個錯誤 – Afshin

+0

你可以添加你的CSS嗎?爲什麼在第一個代碼塊中有點擊功能,然後在第二個塊中有不同的點擊功能? – jmore009

回答

0

您可以使用一個回調函數.animate()將運行第二個動畫的第一個完成後:

$(".counsel-b").click(function(){ 
    $(".order-t").animate({top:'52%'}, "slow", function(){ 
     $(".counsel-t").animate({top:'30%'}, "slow"); 
    });   
}); 

FIDDLE

+0

你知道嗎?這個問題中沒有提到每個div的動畫。所以,如果我想爲他們所有人做這個,那麼會有一個真正的垃圾。我正在尋找一個簡短的代碼來做到這一點。 – Afshin

+0

如果您需要特定問題的幫助,您需要發佈確切的問題。這就是你如何去做,並且儘可能短 – jmore009

相關問題