How to measure the milliseconds between mousedown and mouseup?

Viewed 41536

Is there any way to measure the number of milliseconds between mouse press and release?

6 Answers

I think this is the most elegant way:

 function onMouseDown(e) {
    window.onmouseup = function(e2) {
      var diff = e2.timeStamp - e.originalEvent.timeStamp;
      console.log(diff);
      window.onmouseup = null;
    };
  }
Related