What is the best way to pause in JavaScript. I have attempted to use the setTimeout() function before, but I really got confused on how it works.
Asked
Active
Viewed 451 times
1
-
2pausing what? what are trying to accomplish? – Fabrizio Calderan Mar 29 '12 at 15:51
-
1and possible duplicate of [Javascript sleep](http://stackoverflow.com/questions/951021/javascript-sleep) – Fabrizio Calderan Mar 29 '12 at 16:05
1 Answers
0
var pauseTime = 1000; //this is in milliseconds
setTimeout(runThisFunction,pauseTime);
function runThisFunction(){
alert("i waited a second to run!");
}
it works by waiting x milliseconds then calls the function you pass .. in this case the function name is runThisFunction

samccone
- 10,746
- 7
- 43
- 50
-
If you replace the alert with a print statement, it will NOT guarantee that the function will run for x milliseconds. – user1187968 Mar 29 '12 at 16:36