jQuery Animation Delay

我与影子孤独终老i 提交于 2019-12-07 04:14:01

问题


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});
    });
});

回答1:


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

jsFiddle example




回答2:


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


来源:https://stackoverflow.com/questions/6986655/jquery-animation-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!