睡在JQuery? [英] Sleep in JQuery?
本文介绍了睡在JQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候所有
i希望让JQuery在两个函数之间休眠/等待一秒
greetings all i want to make JQuery sleep/wait for a second between two functions
$('#div1').hide();
//sleep or wait or for a sec
$("#div2").show();
怎么办?
推荐答案
对于您的特定功能 .show()
没有排队,但有一个简单的技巧让它排队,所以你可以使用 .delay()
,如下所示:
For your specific function .show()
isn't queued, but there's an easy trick to make it queued so you can use .delay()
, like this:
$('#div1').hide();
$("#div2").delay(1000).show(0);
通过给它一个 0
持续时间参数,它现在是一个即时但排队的动画。下面使用 setTimeout()
,所以它是基本上与以下行为相同:
By giving it a 0
duration argument, it's now an instant, but queued animation. Underneath this uses setTimeout()
, so it's basically the same behavior as:
$('#div1').hide();
setTimeout(function() { $("#div2").show(); }, 1000);
这篇关于睡在JQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文