JavaScript delay repetitive execution function llooprun.js_javascript technique
Source: Internet
Author: User
function Llooprun (sfuncloop,sfuncend,ndelay) {
Writen by http://fengyan.iecn.cn
Sfuncloop >> String type, JavaScript functions or statements that need to be executed repeatedly (multiple functions or statements, separate)
Sfuncend >> string, JavaScript function or statement used to abort a repeating action (Sfuncloop)
Ndelay >> Digital, repeat time interval (milliseconds)
var vintervalid = null;
var runstring = Sfuncloop;
var stopstring = sfuncend;
var delaytime = Ndelay;
var ncount = 0;//Number of executions//To facilitate testing, the line is commented out when applied
This._doloop = function () {
if (Vintervalid &&!eval (stopstring)) {
eval (runstring);
ncount++;//record number of executions//To be easy to test, comment out the line when applied
} else {
Window.clearinterval (Vintervalid);
Vintervalid = null;
}
document.getElementById ("Testcount"). InnerHTML = ncount;//output execution times//To facilitate testing, the line is commented out when applied
}
Window.clearinterval (Vintervalid);
Vintervalid = Window.setinterval (this._doloop,delaytime);
}
Several instance code:
Horizontal Reciprocating movement:
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