Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Animation Delay

How do I delay animation with jQuery?

I need to get a navigation to expand the width, and then expand the height, and then reversed for the reverse animation.

Code:

$(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});
    });
});
like image 438
JacobTheDev Avatar asked Aug 08 '11 18:08

JacobTheDev


2 Answers

use the jQuery .delay(N) methods, where N is the milliseconds to delay.

jsFiddle example

like image 192
Madara's Ghost Avatar answered Sep 30 '22 22:09

Madara's Ghost


Here is the call you are looking for http://api.jquery.com/delay/

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

use is as follows

$.animate(action1).delay(n).animate(action2)
// this code puts the delay bewtween two different animations
like image 37
Bill Bonar Avatar answered Sep 30 '22 23:09

Bill Bonar