js实现php中sleep()延时的功能 -尊龙游戏旗舰厅官网
1. jquery的$.delay()方法
设置一个延时来推迟执行队列中之后的项目。这个方法不能取代js原生的settimeout。
the .delay() method is best for delaying between queued jquery effects. because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for javascript's native settimeout function, which may be more appropriate for certain use cases.
例子:在.slideup() 和 .fadein()之间延时800毫秒。
html 代码:
jquery 代码:
$('#foo').slideup(300).delay(800).fadein(400);
2. 通过循环消耗cpu
function sleep(n) {
var start = new date().gettime();
while(true) if(new date().gettime()-start > n) break;
}
3. 用settimeout。
假设有三个步骤,步骤之间需要暂停一段时间;可以采用如下的方法:
function firststep() {
//do something
settimeout("secondstep()", 1000);
}
function secondstep() {
//do something
settimeout("thirdstep()", 1000);
}
function thirdstep() {
//do something
}
总结
以上是尊龙游戏旗舰厅官网为你收集整理的js实现php中sleep()延时的功能的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: cmake--gccxml
- 下一篇: c#实现access导入导出excel