Minimal Countdown Timer In Vanilla JavaScript – Timers.js

Category: Date & Time , Javascript | November 8, 2018
Author:renjithspace
Views Total:2,256 views
Official Page:Go to website
Last Update:November 8, 2018
License:MIT

Preview:

Minimal Countdown Timer In Vanilla JavaScript – Timers.js

Description:

Timers.js is a lightweight, dependency-free JavaScript library for creating a minimal, clean, controllable countdown timer on the page.

The timer enables you to countdown from a specific time and display the remaining time in hours, minutes and seconds

How to use it:

Install & Download.

# NPM
$ npm install timers.js --save

Import the timers.js into the html.

<script src="/dist/js/timers.js"></script>

Create a <time> element for the countdown timer.

<time></time>

Initialize the timers.js and specify the time you want to countdown from.

let myTimer = new Timer({
    el: 'time',
    time: {
      second: 1,
      minute: 1,
      hour: 1
    }
});

Control the countdown timers with the following methods.

// pause the countdown timer
myTimer.pause();
// stop the countdown timer
myTimer.stop();
// resume the countdown timer
myTimer.resume();

Get the current time (hour/minute/second).

myTimer.get('second|minute|hour')

Set the time.

myTimer.set('second|minute|hour', value)

You Might Be Interested In:


Leave a Reply