Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add doubleclick event to Canvas element using the "AddEventListener" method?

Tags:

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.

like image 525
marcio Avatar asked Jun 24 '11 03:06

marcio


People also ask

What is double click event?

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.

Is there a double click event in JavaScript?

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.

How do you add an event listener in canvas?

To add a click event to your canvas element, use... canvas. addEventListener('click', function() { }, false);

How do I add an event listener to right click?

addEventListener method to add an event listener function for listening to right clicks. For instance, we can write: window. addEventListener('contextmenu', (ev) => { ev.


1 Answers

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 
like image 127
Pablo Fernandez Avatar answered Sep 22 '22 21:09

Pablo Fernandez