[removed] How to put a simple delay in between execution of javascript code?

前端 未结 5 1118
你的背包
你的背包 2020-12-16 01:45

I have a for loop which iterates more than 10,000 times in a javascript code. The for loop creates and adds < div > tags into a box in the current page DOM.



        
5条回答
  •  隐瞒了意图╮
    2020-12-16 02:33

    You could use the window.setTimeout function to delay the execution of some code:

    if(i % 50 == 0) {
        window.setTimeout(function() {
            // this will execute 1 second later
        }, 1000);
    }
    

    But your javascript will continue to execute. It won't stop.

提交回复
热议问题