I need my code to run x a number of times, and then pause 30 seconds or so before resuming. Any ideas?
myslidefunction(); var tid = setInterval(myslidefunction, 1000); function myslidefunction() { setTimeout(function () { //do stuff }, 400); };
You can save the execution counter and use normal_duration + 30000 as a setTimeout delay for X + 1st time.
normal_duration + 30000
setTimeout
var runCount = 0, runsBeforeDelay = 20; function myslidefunction(){ // .. stuff runCount++; var delay = 0; if(runCount > runsBeforeDelay) { runCount = 0; delay = 30000; } setTimeout(myslidefunction, 400 + delay); }; // start it off setTimeout(myslidefunction, 1000);
var counter = 0; var mySlideFunction = function(){ /* your "do stuff" code here */ counter++; if(counter>=10){ counter = 0; setTimeout(mySlideFunction, 30000); }else{ setTimeout(mySlideFunction, 1000); } } mySlideFunction();
Source: https://habr.com/ru/post/1484454/More articles:Image dialog - continue onOk, not full rewrite - javascriptHow do you browse / find tags in Team Foundation Server 2012 web access? - tfsVarious color markers with jvectormaps - jqueryGet the contents of a text file using javascript - javascriptmysql count occurrences of a special character in a field - phpunusual exit from pow - cDo the main domains and common subdomains have different parts of the same domain model? - domain-driven-designKendo toolbar AddNew button does not work when mesh is filtered - kendo-uiforwarding rdp traffic using netsh - windowsSearchView text color in ActionBar using ActionBarSherlock - androidAll Articles