The preface

Add the explanation from last setInterVal

The disadvantages of setInterVal

  • SetInterval doesn’t care if the code it calls fails. Even if the calling code reported an error, it will continue to call
  • SetInterval ignores network latency. When using Ajax to poll the server for new data, however, no matter what the network condition is, it will send requests over and over again. If the network condition is bad, a request is sent, and no result is returned, it will continue to send requests relentlessly, resulting in requests piling up.
  • SetInterval is not timed. If the code it calls takes less time to execute than the timed time, it will skip the call, which can result in not executing as many times as you need or getting the result you want.
1. In the standard, setInterval() skips the execution of the previous code if it has not completed the execution. 2. In the browser, setInterval() does not skip the previous code execution, but inserts it into a queue and waits for execution immediately after the previous code execution. 3. In Node, setInterval() is executed strictly at intervals.Copy the code
  • SetInterval animations will lag at low frequencies, especially on low-end models

The solution

You can use setTimeout instead, call itself, loop.

Thank github.com/luoxue-vict…