欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程语言 > php >内容正文

php

js实现php中sleep()延时的功能 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 php 20 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 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()延时的功能的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图