Home
Web Front-end
JS Tutorial
Implementation code of pause function in Javascript_javascript skills



Implementation code of pause function in Javascript_javascript skills
May 16, 2016 pm 07:18 PM
Copy code The code is as follows:
<script language="javascript">
/* Implementation of the pause function in Javascript
Javascript itself does not have a pause function (sleep cannot be used) and vbscript cannot use doEvents, so this function is written 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 call var myTest=new Test();myTest.NextStep();
When we pause, we can divide a function into two parts, and the status before the pause operation remains unchanged. Put the code to be executed after the pause in this.NextStep.
In order to control pause and resume, we need to write two functions to implement the pause and resume functions respectively.
The pause function is as follows:
*/
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 ")",1000);
}
/*
This function sets the function to be paused Put it into the array window.eventList, and call the continuation function through setTimeout.
The continued function is as follows:
*/
function GoOn(ind){
var obj=window.eventList[ind];
window.eventList[ind]= null;
if (obj.NextStep) obj.NextStep();
else obj();
}
/*
This function calls the NextStep method of the suspended function, if there is no This method calls the function again.
After the function is written, we can make it as follows:
*/
function Test(){
alert("hellow");
Pause(this, 1000);//Call the pause function
this.NextStep=function(){
alert("NextStep");
}
}
</script>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial

8 Stunning jQuery Page Layout Plugins
