现在的位置: 首页 > 综合 > 正文

javascript sleep pause 实现

2011年05月02日 ⁄ 综合 ⁄ 共 1335字 ⁄ 字号 评论关闭

参考地址:http://edu.codepub.com/2010/0908/25776.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">
.center
{
width
:960px;
margin
:0 auto;
border
:1px solid #333;
background-color
:#ccc;
}
</style>

<script src="jquery-1.4.4.min.js" language="javascript" type="text/javascript">
</script>
<script type="text/javascript">
function load()
{
alert(
"test");
}

function Pause(obj,iMinSecond)
{
if (window.eventList==null) window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++)
{
if (window.eventList[i]==null)
{
window.eventList[i]
=obj;
ind
=i;
break;
}
}

if (ind==-1)
{
ind
=window.eventList.length;
window.eventList[ind]
=obj;
}
setTimeout(
"GoOn(" + ind + ")",iMinSecond);
}
/*
该函数把要暂停的函数放到数组window.eventList里,同时通过setTimeout来调用继续函数。
继续函数如下:
*/
function GoOn(ind)
{
var obj=window.eventList[ind];
window.eventList[ind]
=null;
if (obj.NextStep) obj.NextStep();
else obj();
}
/*
该函数调用被暂停的函数的NextStep方法,如果没有这个方法则重新调用该函数。
函数编写完毕,我们可以作如下册是:
*/
function Test()
{
alert(
"hellow");
Pause(
this,5000);//调用暂停函数
this.NextStep=function()
{
alert(
"NextStep");
}
}
</script>
</head>

<body onload="Test()">

<div class="center">test</div>
</body>
</html>

  

抱歉!评论已关闭.