Javascript 如何在 Jquery 中使用 delay() 和 show() 和 hide()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4508644/
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
How can I use delay() with show() and hide() in Jquery
提问by faressoft
How can I use delay()
with show()
and hide()
in Jquery ?
如何使用delay()
与show()
和hide()
jQuery的?
回答by Felix Kling
回答by Luciano Damiano
The easiest way is to make a "fake show" by using jquery.
最简单的方法是使用 jquery 制作“假节目”。
element.delay(1000).fadeIn(0); // This will work
回答by abhinav1602
Why don't you try the fadeIn()instead of using a show() with delay(). I think what you are trying to do can be done with this. Here is the jQuery code for fadeIn and FadeOut() which also has inbuilt method for delaying the process.
为什么不尝试使用fadeIn()而不是使用带有delay() 的show()。我认为你正在尝试做的事情可以用这个来完成。这是fadeIn 和FadeOut() 的jQuery 代码,它也有用于延迟进程的内置方法。
$(document).ready(function(){
$('element').click(function(){
//effects take place in 3000ms
$('element_to_hide').fadeOut(3000);
$('element_to_show').fadeIn(3000);
});
}
回答by Shakti Singh
from jquery api
来自 jquery api
Added to jQuery in version 1.4, the .delay()
method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed; for example this will not delay the no-arguments forms of .show()
or .hide()
which do not use the effects queue.
在 1.4 版中添加到 jQuery,该.delay()
方法允许我们延迟队列中跟随它的函数的执行。它可以与标准效果队列或自定义队列一起使用。只有队列中的后续事件被延迟;例如,这不会延迟.show()
或.hide()
不使用效果队列的无参数形式。