2011-10-05 77 views
1

我有一個div其中最初顏色是綠色爲什麼動畫和addClass行爲有所不同?

我不明白爲什麼他會立即**得到紅色顏色**,

而動畫是在隊列罰款。

The queue is fine and by order顏色改變立刻

是不是他應該是後第二個動畫

動畫優先級與addClass之間有區別嗎?

$("div").show("slow").animate({left:'+=200'},2000).animate({top:'+=200'},2000).css('background-color','red'); 
+2

注意:您對文本格式的自由使用會導致難以閱讀的問題。當幾乎所有事情都變得大膽起來,看起來很重要時,你必須經過頭腦中的額外步驟來忽略所有格式,以確定問題中「真正*」的重要性。 – Guffa

回答

0

css方法並不穿上動畫隊列的變化,所以當你運行該代碼後會立即改變。

可以使用queue方法把動畫中的隊列中的CSS變化:

$("div").show("slow") 
.animate({left:'+=200'},2000) 
.animate({top:'+=200'},2000) 
.queue(function(){ 
    $(this).css('background-color','red'); 
}); 
0

css不是排隊功能。它立即執行。您可以選擇之間:和

$("div").show("slow").animate({left:'+=200'},2000) 
.animate({top:'+=200'},2000, function(){ $(this).css('background-color','red'); }); 

$("div").show("slow").animate({left:'+=200'},2000).animate({top:'+=200'},2000) 
.queue(function(){ $(this).css('background-color','red'); }); 
0
$("div") 
    .animate({left:'+=200', top:'+=200', display: 'block'}, 2000, 
    function() { 
     $(this).css('background-color','red'); 
    } 
); 

原諒我的縮進。

相關問題