Usually used method:
Start timer:
Method is a js method called regularly
Time is the interval time, the unit is milliseconds
Cancel timer:
Then the question comes. When clearInterval(timerid); is used to clear, it often cannot be stopped immediately. What method is better to solve it?
The optimization plan is as follows
Summary
Generally, setInterval is not used, but the delayed recursion of setTimeout is used instead of interval.
setInterval will produce callback accumulation, especially when the time is short.