tock demonstration
HTML
<script src="https://raw.githubusercontent.com/mrchimp/tock/master/tock.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocktimer/1.0.12/tock.min.js"></script>
<button id="start">start timer</button>
<button id="pause">pause timer</button>
<button id="reset">reset timer</button>
<input id="clock" value="00:00.000"/>
JavaScript
// countdown determines whether the timer will be a countdown timer
// interval determines how often in milliseconds the clock will update
// callback references a function that will be called every time the timer update
var t = new Tock({
countdown:false,
interval:10,
callback:updateClock
});
// first create reference to the timer and control elements
var clock = document.getElementById('clock'),
start = document.getElementById('start'),
pause = document.getElementById('pause'),
reset = document.getElementById('reset');
// then add event listeners to them
start.addEventListener('click',function(){
// start with the current time in the timer
// by passing the current time to the start function
var current = clock.value;
t.start(current);
},false);
pause.addEventListener('click',function(){
t.pause();
},false);
reset.addEventListener('click',function(){
t.reset();
// reset the clock display as well
clock.value = '00:00.000';
},false);
// the callback function is created here
function updateClock(){
clock.value = t.msToTime(t.lap());
}