I'm just trying to add a double click event to a HTML5 Canvas element. It works fine with:
myCanvas.ondbclick
However, I want to use the addEventListener method to do that. I guess it might be a simple task but I googled everywhere and could not find it. What's the name of the event I should be using?
myCanvas.addEventListener('doubleclick?', function(){ // Some dazzling stuff happens be here });
Hope it's possible, don't wanted to "break" my coding consistency.
The dblclick event fires when a pointing device button (such as a mouse's primary button) is double-clicked; that is, when it's rapidly clicked twice on a single element within a very short span of time.
The dblclick event generates an event on double click the element. The event fires when an element is clicked twice in a very short span of time. We can also use the JavaScript's addEventListener() method to fire the double click event.
To add a click event to your canvas element, use... canvas. addEventListener('click', function() { }, false);
addEventListener method to add an event listener function for listening to right clicks. For instance, we can write: window. addEventListener('contextmenu', (ev) => { ev.
The event name is dblclick
:
myCanvas.addEventListener('dblclick', function(){ // Some dazzling stuff happens be here });
Also your first example is wrong, it should say:
myCanvas.ondblclick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With