SoFunction
Updated on 2025-03-03

JavaScript delay repeat execution function

function lLoopRun(sFuncLoop,sFuncEnd,nDelay) {
//writen by 

//sFuncLoop >> String type, Javascript functions or statements that need to be executed repeatedly (please use; separate multiple functions or statements)
//sFuncEnd >> String type, used to abort repeated execution of actions (sFuncLoop) Javascript functions or statements
//nDelay >> Number type, the time interval for repeated execution (milliseconds)
 var vintervalId = null;
 var runString  = sFuncLoop;
 var stopString  = sFuncEnd;
 var delayTime  = nDelay;
//var nCount = 0;//Number of executions//To facilitate testing, this line is commented out when applying
 this._doLoop = function (){
   if (vintervalId && !eval(stopString)){
     eval(runString);
//nCount++;//Record the number of executions//For the convenience of testing, this line is commented out when applying
   } else {
     (vintervalId);
     vintervalId = null;
   }
//("TestCount").innerHTML = nCount;//Output number of executions//For the convenience of testing, this line is commented out when applying
 }
 (vintervalId);
 vintervalId = (this._doLoop,delayTime);
}

Several example codes:
Horizontal reciprocating movement:

<html> 
<head> 
<title> Application Example: Horizontal Reciprocating Movement</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<meta name="Author" content="CnLei,Fengyan" />
<style type="text/css"> 
#IECN {position:absolute;} 
</style> 
<script type="text/javascript" src=""></script>
</head> 
<body> 
<p>Number of executions: <strong >0</strong></p>
<img  src="/attach-iecn/upload/" style="left:0px;top:0px;" width="120" />
<script type="text/javascript">
<!--
function chgPos(sId,n){
 var o = (sId);
  = (parseInt()+n)+"px";
}

function chgPosStop(sId,nMax){
 var o = (sId);
 if(parseInt()<0){isReBack = false;}
 if(parseInt()>nMax){isReBack = true;}
 if(isReBack) {
   nNum=-(nNum);
 } else {
   nNum=(nNum);
 }
}

var nNum=10;
var isReBack = false;
lLoopRun("chgPos(’IECN’,nNum);","chgPosStop(’IECN’,600)",20);
-->
</script>
</body> 
</html> 


Automatic scaling size:
<html> 
<head> 
<title> Application Example: Automatic Scaling</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<meta name="Author" content="CnLei,Fengyan" />
<script type="text/javascript" src=""></script>
</head> 
<body> 
<p>Number of executions: <strong >0</strong></p>
<img  src="/attach-iecn/upload/" style="left:0px;top:0px;" width="120" />
<script type="text/javascript">
<!--

function chgPos(sId,n){
 var o = (sId);
  = (parseInt()+n);
}

function chgPosStop(sId,nMax){
 var o = (sId);
 if(parseInt()<10){isReBack = false;}
 if(parseInt()>nMax){isReBack = true;}
 if(isReBack) {
   nNum=-(nNum);
 } else {
   nNum=(nNum);
 }
 //return parseInt()>nMax || (parseInt()>nMax-200);
}

var nNum=10;
var isReBack = false;
lLoopRun("chgPos(’IECN’,nNum);","chgPosStop(’IECN’,500)",20);
-->
</script>
</body> 
</html> 


Vertical reciprocating motion:
<html> 
<head> 
<title> Application Example: Vertical Reciprocating Movement</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<meta name="Author" content="CnLei,Fengyan" />
<style type="text/css"> 
#IECN {position:absolute;} 
</style> 
<script type="text/javascript" src=""></script>
</head> 
<body> 
<p>Number of executions: <strong >0</strong></p>
<img  src="/attach-iecn/upload/" style="left:0px;top:0px;" width="120" />
<script type="text/javascript">
<!--
function chgPos(sId,n){
 var o = (sId);
  = (parseInt()+n)+"px";
}

function chgPosStop(sId,nMax){
 var o = (sId);
 if(parseInt()<0){isReBack = false;}
 if(parseInt()>nMax){isReBack = true;}
 if(isReBack) {
   nNum=-(nNum);
 } else {
   nNum=(nNum);
 }
 //return parseInt()>nMax || (parseInt()>nMax-200);
}

var nNum=10;
var isReBack = false;
lLoopRun("chgPos(’IECN’,nNum);","chgPosStop(’IECN’,300)",20);
-->
</script>
</body> 
</html> 


Gradient display (picture):
<html> 
<head> 
<title> Application example: Gray display effect</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<meta name="Author" content="CnLei,Fengyan" />
<style type="text/css"> 
body{background:#080;color:#fff;} 
#IECN { 
background:#fff; 
filter: Alpha(opacity=10); 
-moz-opacity:.10; 
opacity:.10;

</style> 
<script type="text/javascript" src=""></script>
</head> 
<body> 
<p>Number of executions: <strong >0</strong></p>
<img  src="/attach-iecn/upload/" style="left:0px;top:0px;" width="120" /><br /><br />Refresh and check the demo effect again
<script type="text/javascript">
<!--
function chgOpacity(sId,n){
 var o = (sId);
 if () {
   [0].Opacity = parseInt([0].Opacity) + n;
 } else {
   = eval((o,null).getPropertyValue(’opacity’)) + (n*100/10000);
 }
}

function chgOpacityStop(sId){
 var o = (sId);
 if () {
   return parseInt([0].Opacity)>=99;
 } else {
   return eval()>=0.99;
 }
}

lLoopRun("chgOpacity(’IECN’,1);","chgOpacityStop(’IECN’)",20);
-->
</script>
</body> 
</html> 


Original text:/