jQuery 如何延迟jquery动画?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3583942/
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-08-26 15:42:19  来源:igfitidea点击:

How to delay jquery animation?

jqueryanimationdelay

提问by user342391

I can't seem to delay the showing of a div. I want to delay the animation by about 20 seconds is this possible???

我似乎无法延迟 div 的显示。我想将动画延迟大约 20 秒这可能吗???

$("#microcharcounter").delay(10000).show();

回答by user113716

Try this:

尝试这个:

$("#microcharcounter").delay(10000).show(0);

or this:

或这个:

$("#microcharcounter").delay(10000).queue(function(n) {
    $(this).show();
    n();
});

The reason for this is that .delay()will only delay items in an animation queue. So you can make .show()a short animation by adding a duration of '0', or add it to the queue with .queue().

这样做的原因是.delay()只会延迟动画队列中的项目。因此,您可以.show()通过添加 '0' 的持续时间来制作短动画,或者将其添加到队列中.queue()

回答by Nick Craver

You can do it like this:

你可以这样做:

setTimeout(function() {
  $("#microcharcounter").show();
}, 20000);

The problem with .delay()and .show()(without a duration), is that .show()isn't an animation, it's an immediate effect that's not on the fxqueue at all. You could however give it a duration, like this:

.delay().show()(没有持续时间)的问题在于,这.show()不是动画,而是根本不在fx队列中的即时效果。但是,您可以给它一个持续时间,如下所示:

$("#microcharcounter").delay(20000).show("fast");