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
Post a Comment