How to pause javascript code excution for 2 seconds -


this question has answer here:

i want stop execution 2 seconds. this, follows code block: hw 10.12

for (var = 1; <=5; i++) { document.write(i); sleep(2);//for first time loop excute , sleep 2 seconds         };  </script> </head> <body> </body> </html> 

for first time loop excute , sleep 2 seconds. want stop execution 2 seconds?

javascript single-threaded, nature there should not sleep function because sleeping block thread. settimeout way around posting event queue executed later without blocking thread. if want true sleep function, can write this:

function sleep(miliseconds) {    var currenttime = new date().gettime();     while (currenttime + miliseconds >= new date().gettime()) {    } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -