Javascript sleep pause implementation

Source: Internet
Author: User

Reference: 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; charsets = UTF-8" />
< Title > Untitled document </ 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 );
}
/*
This function puts the function to be paused in the Array Window. eventlist, and calls the continue function through setTimeout.
The continuation function is as follows:
*/
Function Goon (IND)
{
VaR OBJ = Window. eventlist [ind];
Window. eventlist [ind] = Null ;
If (Obj. nextstep) obj. nextstep ();
Else OBJ ();
}
/*
Call the nextstep method of the suspended function. If this method is not available, call the function again.
After the function is compiled, we can perform the following operations:
*/
Function Test ()
{
Alert ( " Hellow " );
Pause ( This , 5000 ); // Call the pause function
This . Nextstep = Function ()
{
Alert ( " Nextstep " );
}
}
</ Script >
</ Head >

< Body Onload = "Test ()" >

< Div Class = "Center" > Test </ Div >
</ Body >
</ Html >

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.