zoukankan      html  css  js  c++  java
  • javascript sleep pause 实现

    参考地址: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>

      

  • 相关阅读:
    Java中sleep方法和wait的详细区别
    判断一个字符串中出现次数最多的字符,统计这个次数
    截取字符串abcdefg的efg
    关于正则
    css 的清0
    关于alert
    新感知,可以创建自定义标签
    JS的组成部分
    把字符串首字母变成大写
    排序方法两两对比
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2130708.html
Copyright © 2011-2022 走看看