Skip to main content
added 152 characters in body
Source Link
Raj Nandan Sharma
  • 3.9k
  • 3
  • 35
  • 44

I had the same problem once this is how I solved it.

Suppose I want 12 delays with an interval of 2 secs

    function animate(i){
         myVar=setTimeout(function(){
            alert(i);
            if(i==12){
              clearTimeout(myVar);
              return;
            }
           animate(i+1)
         },2000)
    }
    
    var i=1; //i is the start point 1 to 12 that is
    animate(i); //1,2,3,4..12 will be alerted with 2 sec delay

I had the same problem once this is how I solved it.

Suppose I want 12 delays with an interval of 2 secs

function animate(i){
     myVar=setTimeout(function(){
        alert(i);
        if(i==12){
          clearTimeout(myVar);
          return;
        }
       animate(i+1)
     },2000)
}

animate(i);

I had the same problem once this is how I solved it.

Suppose I want 12 delays with an interval of 2 secs

    function animate(i){
         myVar=setTimeout(function(){
            alert(i);
            if(i==12){
              clearTimeout(myVar);
              return;
            }
           animate(i+1)
         },2000)
    }
    
    var i=1; //i is the start point 1 to 12 that is
    animate(i); //1,2,3,4..12 will be alerted with 2 sec delay
Source Link
Raj Nandan Sharma
  • 3.9k
  • 3
  • 35
  • 44

I had the same problem once this is how I solved it.

Suppose I want 12 delays with an interval of 2 secs

function animate(i){
     myVar=setTimeout(function(){
        alert(i);
        if(i==12){
          clearTimeout(myVar);
          return;
        }
       animate(i+1)
     },2000)
}

animate(i);