countdowntimer.js中的停止/恢复/重启功能



我在一个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()方法。

最新更新