Loop is more important than rest?

后端 未结 4 1719
旧巷少年郎
旧巷少年郎 2021-01-14 07:12

I want to execute simple code when user click on my button:

  1. First: change my cursor to \'wait\'
  2. Next: execute loop
  3. When loop is finished: cha
4条回答
  •  [愿得一人]
    2021-01-14 07:51

    Your styles are applied only after the call stack has finished. You can separate this into two different call stacks by running the second half of the function from a setInterval like this:

    var progress = document.getElementById('progress');
    
    document.getElementById('gogogo').onclick = (function(){
        document.body.style.cursor = 'wait';
    
        setTimeout(function(){
    
            for(var ii = 0; ii < 30000; ii += 1){
                progress.textContent = ii;
            }
    
            document.body.style.cursor = 'default';
        }, 0);
    
    });
    

提交回复
热议问题