Chrome会降低javascript倒计时器的速度 [英] Chrome slows down javascript countdown timer

查看:177
本文介绍了Chrome会降低javascript倒计时器的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JS中有一个倒数计时器在IE中运行良好但是在Chrome中,标签变为非活动状态会降低计时器的速度



我尝试了什么:



我尝试以900毫秒的速度触发事件并应用延迟时间100毫秒但仍无法正常工作设置超时100毫秒无法正常工作

I have a countdowntimer in JS works well in IE but in chrome as tab goes inactive it slows down timer

What I have tried:

I tried firing event at 900 milisecond and applied delay og 100 ms but still doesnot work settimeout for 100ms is not working

推荐答案

建议:计时器很适合在大多数常规时间启动一段代码,但对于倒计时时间不准确。

使用计时器知道何时需要刷新显示。

对于时间倒计时,请使用RTC(实时时钟)。倒计时是now()和截止日期之间的差异。
Advice: Timer is good at launching a piece of code at mostly regular timings, but is not accurate for time countdown.
Use the timer to know when you need to refresh display.
For the time countdown, use the RTC (Real Time Clock). The countdown is the difference between now() and a deadline.


这是Chrome的故意功能。其他浏览器显然也在考虑采用它。

干预:限制昂贵的背景计时器·问题#34 ·WICG /干预措施·GitHub [ ^ ]

Chrome 57中的背景标签  | 网络  |  Google开发者 [ ^ ]



此StackOverflow主题中有一些建议:

javascript - 当Chrome中的标签处于非活动状态时,如何使setInterval也能正常工作? - 堆栈溢出 [ ^ ]
This is a deliberate "feature" of Chrome. Other browsers are apparently considering adopting it as well.
Intervention: Throttle expensive background timers · Issue #34 · WICG/interventions · GitHub[^]
Background Tabs in Chrome 57  |  Web  |  Google Developers[^]

There are some suggestions in this StackOverflow thread:
javascript - How can I make setInterval also work when a tab is inactive in Chrome? - Stack Overflow[^]


这篇关于Chrome会降低javascript倒计时器的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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