I need a function that determines whether the user clicks by double-clicking or dragging the mouse.
Since everything that happens on one canvas using ordinary events does not work. I found this via google:
It is not recommended to associate handlers with both a click and dblclick events for the same element. The sequence of triggered events varies from browser to browser, with some receiving two click events and others receiving only one. If an interface that responds differently to single and double clicks cannot be avoided, then the dblclick event should be modeled in the click handler. We can achieve this by storing the timestamp in the handler, and then comparing the current time with the saved timestamp on subsequent clicks. If the difference is small enough, we can consider the click as a double click.
How can I achieve this in a good way?
First see if a click is clicked (for drag and drop)? When it's released, treat it like a click? and then, if you double-click, double-click?
How can I translate this into code? Help evaluate.
javascript html5 event-handling canvas
justanotherhobbyist
source share