html5中文学习网

您的位置: 首页 > 网站及特效实例 > javascript特效 » 正文

JavaScript实现Sleep函数的代码_javascript技巧_

[ ] 已经帮助:人解决问题
复制代码 代码如下:

function Sleep(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);
 }
 function GoOn(ind)
 { 
  var obj=window.eventList[ind];
  window.eventList[ind]=null;
  if (obj.NextStep) obj.NextStep();
  else obj();
 }
 function Test()
 { 
  alert("sleep"); 
  Sleep(this,100);
  this.NextStep=function()
  { 
  alert("continue");
  }
 }
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助