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 -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -