@lxfriday/countdown

1.0.2 • Public • Published

countdown

javascript auto countdown util class

install

npm i @lxfriday/countdown -S
# or
yarn add @lxfriday/countdown

params

constructor

  • leftTime {number} required time(second) left for countdown
  • i {number} period time(second) to execute onDown

CountDown.prototype.onDown

called every period, hack func

// use

CountDown.prototype.onDown = function (leftTime) {
    console.log(leftTime);
}

CountDown.prototype.start

start countdown

CountDown.prototype.pause

pause countdown temporarily

CountDown.prototype.stop

stop countdown

CountDown.prototype.reset

reset the available time to initial time

CountDown.prototype.restart

restart countdown using the initial leftTime

usage

var CountDown = require('@lxfriday/countdown');

var countdown1 = new CountDown(180);
countdown1.onDown = function (leftTime) {
    console.log('time now left: ' + leftTime + ' second(s)');
}

countdown1.start();

// time now left: 179 seconds(s)
// time now left: 178 seconds(s)
// time now left: 177 seconds(s)
// time now left: 176 seconds(s)

countdown1.pause(); // temporarily pause

countdown1.start();

// time now left: 175 seconds(s)
// time now left: 174 seconds(s)

countdown1.stop(); // now stoped

// if you want to restart, call reset and start

countdown1.reset();
countdown1.start();

// 179
// 178 ...

// or call restart

countdown1.restart();

// 179
// 178 ...

/@lxfriday/countdown/

    Package Sidebar

    Install

    npm i @lxfriday/countdown

    Weekly Downloads

    0

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    5.27 kB

    Total Files

    5

    Last publish

    Collaborators

    • lxfriday