I am trying to make timer start when mouse button is down using mouseDown function and stop timer when mouse button is up with mouseUp function
Here is code which i got:
var startTime;
function display() {
// later record end time
var endTime = new Date();
// time difference in ms
var timeDiff = endTime - startTime;
// strip the miliseconds
timeDiff /= 1;
// get seconds
var seconds = Math.round(timeDiff % 100000000);
$(".time").text(seconds);
setTimeout(display, 1);
}
$(canvas).click(function () {
startTime = new Date();
setTimeout(display, 1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas height="420" style="background:#e4e1e1" id="canvas" width="540"></canvas>
<div class="time"></div>