How to force repaint in JS?

前端 未结 3 1006
-上瘾入骨i
-上瘾入骨i 2020-12-21 23:53

What I am trying to achieve:

  1. user clicks on an element
  2. the screen shows the \"calculation in progress\" screen
  3. the system performs time-consu
3条回答
  •  心在旅途
    2020-12-22 00:25

    You need to either wait a millisecond or do the calculations with a Worker.

    The first example is probably the easiest, instead of calling calc directly, create a new function

    function caller() {
         // insert "calculation in progress" in the body
        setTimeout(calc, 1);
    }
    

    Then call caller.

提交回复
热议问题