Javascript sleep/delay/wait function

后端 未结 6 1202
时光取名叫无心
时光取名叫无心 2021-01-03 23:13

Sorry if this question has already been asked here before, I could not find a suitable answer.

I am wanting to create a JavaScript sleep/delay/wait function that I c

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 00:11

    You can use this -

    function sleep(milliseconds) {
        var start = new Date().getTime();
        for (var i = 0; i < 1e7; i++) {
            if ((new Date().getTime() - start) > milliseconds){
                break;
            }
        }
    }
    

提交回复
热议问题