First link to the script
<script src="https://cdn.jsdelivr.net/npm/@caleb1248/timerjs@1.0.1"></script>
<script src="https://cdn.jsdelivr.net/npm/@caleb1248/timerjs@1.0.1"></script>
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
const timer = new Timer();
timer.start()
timer.stop()
timer.setTime(hours, minutes, seconds)
on(event, callback)
Usage
timer.on('start', function() {
console.log('timer started');
});
// Or
timer.onstart = function() {
console.log('timer started');
}
timer.on('stop', function() {
console.log('timer stopped');
})
// Or
timer.onstop = function() {
console.log('timer stopped');
}
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);
}
timer.on('timerend', function() {
console.log('event fired');
})
// Or
timer.ontimerend = function() {
alert('Times up!');
}