NextGen123
NextGen123

Reputation: 293

JS - calc duration of mouseclick

I wonder if there is any way to calculate mouse click in seconds.

Just to make it clear, if user keeps the mousedown for 5 seconds, I wanna write to console '5 sec' etc.

There is any way to do it?

Thanks!

Upvotes: 2

Views: 1495

Answers (2)

OgzhnOzlci
OgzhnOzlci

Reputation: 56

Get a startDate on mouseDown then get endDate on mouseUp and calculate difference between these dates, convert second. And.... just console.log :)

Upvotes: 2

Loufylouf
Loufylouf

Reputation: 699

Well, I think you should have a look at the Date object in Javascript, as well as to the events being fired during a click (mousedown is not the only one).

Upvotes: 2

Related Questions