如何暂停计时器或冻结计时器并恢复->javascript [英] how to pause timer or freeze it and resume -> javascript
问题描述
我正在用javascript做一个小应用程序,周围有一些计时器.在某些时候,我需要更改单个计时器在运行时使用的变量.
I am doing a little app in javascript that has some timers around. At some point I need to change the variables that a single timer is using during runtime.
我尝试了一次只是更改变量(例如以10为单位递增)的计时,但计时器仍会产生怪异的行为.因此,我发现必须首先停止计时器,更改变量,然后再恢复它(但仍然不可行).
I tried a coiple of times just changing the variable (incrementing it, for instance in 10 units) still the timer will have a weird behavior. So I figured out that the timer must be stopped first, change the variable and after that resume it (but still dunno this is possible).
我想问的是:有什么方法可以暂停计时器功能然后恢复它吗?
What I want to ask is: there is any way to pause a timer function and then resume it?
变量不是计时器的局部变量(它们是全局变量)
the variables are not local for the timer (they are global)
推荐答案
var t1;
t1 =setTimeout("dosomethig",1000) //1000 = 1 sec
clearTimeout(t1); // to release timeout
这篇关于如何暂停计时器或冻结计时器并恢复->javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!