alorel / alo-timer
此包已被放弃,不再维护。未建议替代包。
当您需要精度时,这是一个简单的倒计时类
1.1
2015-08-14 14:16 UTC
This package is not auto-updated.
Last update: 2022-02-01 12:49:20 UTC
README
对于大多数事情,简单的 setTimeout()
或 setInterval()
就足够了 - 但是当页面最小化/切换到标签页时,JavaScript 定时器会被节流,最终导致长时间运行的不精确计时。这就是 AloTimer 发挥作用的地方 - 您设置一个计时器,并以所需的精度轮询它 - 虽然单个轮询调用可能会被节流,但最终结果始终是准确的。
功能
- 添加或减去毫秒/秒/分钟/小时/天数
- 单独获取上述任何数量的剩余时间
- 以 DD:HH:mm:ss 字符串形式输出剩余时间(可定制)
- 检查超时是否完成
- 暂停和恢复计时器
安装
<script src="path-to-alotimer.min.js"></script>
或者,如果您更喜欢 Node,
npm install alo-timer --save
使用示例
var span = document.getElementById("my-countdown"), timer = new AloTimer(3600000, ["hours", "minutes", "seconds"]), // 1 hr intervalCb = function () { if (!timer.hasFinished) { span.innerText = timer.toString(); } else { span.innerText = "YOUR SCHNITZEL IS DONE!"; clearInterval(interval); } }, interval = setInterval(intervalCb, 1000);
更多信息