Changing the interval of SetInterval while it's running

后端 未结 16 1282
南旧
南旧 2020-11-22 07:35

I have written a javascript function that uses setInterval to manipulate a string every tenth of a second for a certain number of iterations.

function timer(         


        
16条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 08:11

    Simple answer is you can't update an interval of already created timer. (There is only two functions setInterval/setTimer and clearInterval/clearTimer, so having a timerId you can only deactivate it.) But you can made some workarounds. Take a look at this github repo.

提交回复
热议问题