JavaScript CountDown v1.0

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript CountDown v1.0相关的知识,希望对你有一定的参考价值。

/*
**************************************
* CountDown Class v1.0               *
* Autor: Carlos R. L. Rodrigues      *
**************************************
*/
CountDown = function(){
    this.date = !(this.finished = this.paused = false);
}
CountDown.prototype.start = function(n, e, t, r){
    var o = this;
    r ? o.onResume && o.onResume(o.n) :
    (o.n = o.date ? new Date(n).getTime() : n, o.e = o.date ? new Date(e).getTime() : e,
    o.t = t, o.finished = false, o.onStart && o.onStart(o.n));
    o.d = e < n ? 1 : -1, o.paused = false, o.i = setInterval(function(){
        o.d * (o.n -= o.d * (o.date ? 1e3 : 1)) <= o.e * o.d &&
        (o.finished = !o.stop()) && !clearInterval(o.i) ||
        o.onUpdate && o.onUpdate(o.n);
    }, (o.t || 1) * 1e3);
}
CountDown.prototype.pause = function(t){
    var o = this;
    clearTimeout(o.x), o.paused ? o.start(o.n, o.e, o.t, 1) :
    (o.paused = !clearInterval(o.i), o.onPause && o.onPause(o.n),
    t && (o.x = setTimeout(function(){
        o.start(o.n, o.e, o.t, 1);
    }, t * 1e3)));
}
CountDown.prototype.stop = function(){
    var o = this;
    clearInterval(o.i), clearTimeout(o.x), o.onStop && o.onStop(o.n), o.n = 0;
}

以上是关于JavaScript CountDown v1.0的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript Javascript HTTP请求v1.0

JavaScript 总和v1.0

JavaScript 限制v1.0

JavaScript 日期格式v1.0

JavaScript 等于v1.0

JavaScript 块v1.0