jquery - run a function inside FOR every 10 seconds -


i have inside script:

for(var = 0, l = eachline.length; < l; i++) {  if(eachline[i].length>0){   dop(eachline[i], +i);  } } 

the read lines string , call dop function. happens is fast , cause speed trouble in webside depending on text size.

what want call dop function every 10 seconds... in other words, want wait 10 seconds call dop function again... how can make work?

using setinterval()

var = 0, len = eachline.length; function looper(){     if(i == 0)         interval = setinterval(looper, 10000)     if(eachline[i].length > 0)         dop(eachline[i], ++i);     if(i >= len)          clearinterval(interval); } looper(); 

var eachline = ["hi", "there", "i", "am", "lines", "of", "text"];  var = 0, len = eachline.length;  function looper(){      if(i == 0)          interval = setinterval(looper, 2000)      if(eachline[i].length > 0)          dop(eachline[i], ++i);      if(i >= len)           clearinterval(interval);  }  looper();    function dop(line, count){      $('body').append(count + ": " + line + "<br/>");  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

using settimeout()

var = 0, len = eachline.length; function looper(){     if(eachline[i].length > 0)         dop(eachline[i], ++i);     if(i < len)          settimeout(looper, 10000); } looper(); 

var eachline = ["hi", "there", "i", "am", "lines", "of", "text"];  var = 0, len = eachline.length;  function looper(){      if(eachline[i].length > 0)          dop(eachline[i], ++i);      if(i < len)           settimeout(looper, 2000);  }  looper();    function dop(line, count){      $('body').append(count + ": " + line + "<br/>");  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -