2011-10-05 68 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'); 
    } 
); 

原谅我的缩进。

相关问题