@caleb1248/timerjs
v1.0.1
Published
First link to the script ## Regular javascript ```html <script src="https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.min.js"></script> ``` ### Or ```html <script src="https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.js
Downloads
6
Readme
Timerjs: Simplifing online timers
How to
First link to the script
Regular javascript
<script src="https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.min.js"></script>
Or
<script src="https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.js"></script>
ES Javascript
// import the minified version
import Timer from 'https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.esm.min.js'
// Or the regular version
import Timer from 'https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.esm.js'
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
You can install this as an npm package too at https://www.npmjs.com/package/npmtimerjs. A nodejs example is at https://www.npmjs.com/package/npmtimerjs-example