如何暂停计时器或冻结它并恢复 ->javascript [英] how to pause timer or freeze it and resume -> javascript

查看:26
本文介绍了如何暂停计时器或冻结它并恢复 ->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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆