This article describes the implementation of JS custom Web page Drag class. Share to everyone for your reference, specific as follows:
JavaScript does not have a pause function (sleep cannot be used) while VBScript cannot use DoEvents, so writing this function implements this function.
JavaScript as a weak object language, a function can also be used as an object.
Like what:
function Test () {
alert ("Hellow");
This. Nextstep=function () {
alert ("NextStep");
}
We can call var mytest=new Test (); Mytest.nextstep ();
We can do it when we're done. A function is divided into two parts, the same before the pause operation, put the code to be executed after the pause in this. In NeXTSTEP.
To control pause and continue, we need to write two functions to implement the pause and continue function separately.
The pause function is as follows:
<script language= "JavaScript" > Function sleep (obj,iminsecond) {if (Window.eve
Ntlist==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 places the function to be paused in the array window.eventlist and calls the continuation 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 ();
}/* The function calls the NeXTSTEP method of the function being paused, and calls the function again if there is no such method.
Once the function has been written, we can do the following: */function Test () {alert ("Hellow"); Sleep (this,3000);/call suspend function this.
Nextstep=function () {alert ("NextStep");
} Test (); </script>
Hope this article will help you learn about JavaScript programming.