javascript - countdowntimer.js 中的停止/恢复/重新启动功能

标签 javascript jquery countdowntimer

我已经在一个 html5 游戏中加入了一个倒计时器,我目前正在使用以下 javascript 库。

https://cdn.rawgit.com/robbmj/simple-js-countdown-timer/master/countdowntimer.js

window.onload = function () {
var display1 = document.querySelector('#time1'),
    display2 = document.querySelector('#time2'),
    timer1 = new CountDownTimer(5),
    timer2 = new CountDownTimer(10);

timer1.onTick(format(display1)).onTick(restart).start();
timer2.onTick(format(display2)).start();

function restart() {
    if (this.expired()) {
        setTimeout(function () { timer1.start(); }, 1000);
    }
}

function format(display) {
    return function (minutes, seconds) {
        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;
        display.textContent = minutes + ':' + seconds;
    };
}

http://jsfiddle.net/robbmj/vpq5toeq/4/

有什么方法可以使用上述库停止/恢复和重新启动计时器。

最佳答案

您链接到的库不提供任何暂停或停止功能。

添加某种形式的暂停/恢复功能相对简单,因为该库只有几行长。可能类似于名为 pausedpause()resume() 方法的实例变量。

关于javascript - countdowntimer.js 中的停止/恢复/重新启动功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30352791/

相关文章:

jQuery Mobile 面板无法正常工作

javascript - 基于 jQuery 的 Splitter 插件

javascript - javascript函数变量数据如何传递到另一个页面

javascript - CasperJS 在 AngularJS 上运行不佳

javascript - 触发卸载导致错误

ios - 如何快速修复 "Cannot subscript a value of type ' ClosedRange<Int >' with an index of type ' Int'

java - 如何在所有 Activity 中显示 Timer 的剩余时间?

Javascript 数组操作

javascript - jquery 更改所选 div 的背景颜色

android - CountdownTimer:当用户返回上一个 Activity 时,如何从剩余时间重新开始?