How does javascript pause and javascript pause?
This example describes the custom webpage drag class implemented by JS. We will share this with you for your reference. The details are as follows:
Javascript itself does not have the pause function (sleep cannot be used) and vbscript cannot use doEvents. Therefore, write this function to implement this function.
Javascript is a weak object language, and a function can also be used as an object.
For example:
function Test(){ alert("hellow"); this.NextStep=function(){ alert("NextStep"); } }
We can callVar myTest = new Test (); myTest. NextStep ();
When we pause a function, we can divide it into two parts, which are unchanged before the pause operation and put the code to be executed after the pause in this. NextStep.
To control the pause and continue, we need to write two functions to implement the pause and continue functions respectively.
The pause function is as follows:
<Script language = "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);}/* put the function to be paused in the Array window. event List, and call the continue function through setTimeout. The continue 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 writing the function, we can do the following: */function Test () {alert ("hellow"); sleep (this, 3000); // call the pause function this. nextStep = function () {alert ("NextStep") ;}} Test (); </script>
I hope this article will help you learn about javascript programming.