How to create pause or delay in FOR loop?

前端 未结 12 1543
长情又很酷
长情又很酷 2021-02-01 19:57

I am working on a website, where I need to create a pause or delay.
So please tell me How to create pause or delay in for loop in javascript or

12条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 20:20

    I used a do...while loop to put a delay in my code for a modal dialog that was closing too quickly.

    your stuff....
    
    var tNow = Date.now();
    var dateDiff = 0;
    do {
        dateDiff = Date.now() - tNow;
    } while (dateDiff < 1000); //milliseconds - 2000 = 2 seconds
    
    your stuff....
    

提交回复
热议问题