javascript jQuery 动画延迟

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6986655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:36:09  来源:igfitidea点击:

jQuery Animation Delay

javascriptjqueryanimationdelay

提问by JacobTheDev

How do I delay animation with jQuery?

如何使用 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});
    });
});

回答by Madara's Ghost

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

使用 jQuery.delay(N)方法,其中 N 是要延迟的毫秒数。

jsFiddle example

jsFiddle 示例

回答by Bill Bonar

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

这是您正在寻找的电话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