2011-08-08 11 views
5

jQueryを使用してアニメーションを遅延させるにはどうすればよいですか?jQuery Animation Delay

ナビゲーションを取得して幅を広げてから、高さを広げて、逆のアニメーションを逆にする必要があります。

コード:

$(function() { 
    $("#nav li").not("#logo, #nav li ul li").hover(function(){ 
     $(this).animate({width:"200px"},{queue:false,duration:1000}); 
    }, function(){ 
     $(this).animate({width:"30px"},{queue:false,duration:1000}); 
    }); 


    $("#nav li.parent").hover(function(){ 
     $(this).children("ul").animate({height:"40px"},{queue:false,duration:500}); 
    }, function(){ 
     $(this).children("ul").animate({height:"0px"},{queue:false,duration:500}); 
    }); 
}); 

答えて

9

Nが遅延するミリ秒であるjQueryの.delay(N)方法を、使用。ここで

jsFiddle example

+1

私はあなたのjsFiddleがこれを片付けるだろうと仮定していますが、どこが正確に行いますが、次のようにあなたがhttp://api.jquery.com/delay/

.delay(n) // where n is the millis of delay 

使用を探しているコールがあるありますそのコードのビットは行く?私はjQueryの新機能ですので、noobの質問についてはごめんなさい – JacobTheDev

+0

アニメーションの間には、jsFiddleを追加しました。 –

+0

ああ、わかりましたが、私のコード例のように2つの異なるホバー状態にしたい場合はどうでしょうか? – JacobTheDev

4

$.animate(action1).delay(n).animate(action2) 
// this code puts the delay bewtween two different animations