Skip to content

caleb1248/timerjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Timerjs: Simplifing online timers

How to

First link to the script

Regular javascript

<script src="https://cdn.jsdelivr.net/npm/@caleb1248/timerjs@1.0.1"></script>

Or

<script src="https://cdn.jsdelivr.net/npm/@caleb1248/timerjs@1.0.1"></script>

ES Javascript

import Timer from "https://cdn.jsdelivr.net/npm/@caleb1248/timerjs@1.0.1/dist/timer.esm.js"

You can also install the timerjs on npm using the following command:

npm i @caleb1248/timerjs

Usage:

const timer = new Timer();

Methods:

Start the timer

timer.start()

Stop the timer

timer.stop()

Set the time on the timer (stops the timer as well)

timer.setTime(hours, minutes, seconds)

Handle events...

on(event, callback)

Events that are fired:

start

Usage

timer.on('start', function() {
  console.log('timer started');
});
// Or
timer.onstart = function() {
  console.log('timer started');
}

stop

timer.on('stop', function() {
  console.log('timer stopped');
})
// Or
timer.onstop = function() {
  console.log('timer stopped');
}

update

timer.on('update', function(hours, minutes, seconds) {
  console.log('timer updated', hours, minutes, seconds);
})
// Or
timer.onupdate = function(hours, minutes, seconds) {
  console.log('timer updated', hours, minutes, seconds);
}

timerend

timer.on('timerend', function() {
  console.log('event fired');
})
// Or
timer.ontimerend = function() {
  alert('Times up!');
}

View an example here

View the source code for the example here

I also posted a nodejs example here.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published