function lLoopRun(sFuncLoop,sFuncEnd,nDelay) {
//written by http://fengyan.iecn.cn
//sFuncLoop >> String type, Javascript function or statement that needs to be executed repeatedly (please use; to separate multiple functions or statements)
//sFuncEnd >> String type, a Javascript function or statement used to terminate repeated execution of actions (sFuncLoop)
//nDelay >> Numeric type, time interval for repeated execution (number of milliseconds)
var vintervalId = null;
var runString = sFuncLoop;
var stopString = sFuncEnd;
var delayTime = nDelay;
//var nCount = 0;//Number of executions//For the convenience of testing, comment out this line when applying
this._doLoop = function (){
if (vintervalId && !eval(stopString)){
eval(runString);
//nCount ;//Record the number of executions//For the convenience of testing, comment out this line when applying
} else {
window.clearInterval(vintervalId);
vintervalId = null;
}
//document.getElementById("TestCount").innerHTML = nCount;//Output the number of executions//For the convenience of testing, comment out this line when applying
}
window.clearInterval(vintervalId);
vintervalId = window.setInterval(this._doLoop,delayTime);
}
A few example codes:
Horizontal reciprocating motion:
Number of executions:
0