0

Can i double click addEventListener ??

I want to click "click" and "contextmenu" at the same time Is it possible?

12th Dec 2021, 7:09 AM
곽민우
곽민우 - avatar
4 Respostas
+ 3
How could it be? click detects left mouse button, contextmenu detects right mouse button. And why you want this?
12th Dec 2021, 7:47 AM
Ipang
+ 3
I don't know if that's possible. As I understand it, addEventListener() accepts one event name and a function assigned as the event handler.
12th Dec 2021, 9:20 AM
Ipang
+ 1
Interesting idea. vanilla JavaScript does not detect two mouse event at the same time. The MouseEvent.button property tells you which button is pressed to trigger the event. https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button To achieve what you wanted to do, You need to use two global variables, one for remembering whether Left Mouse button is clicked, the other one for remembering whether Right Mouse button is clicked. You can then define a callback function which check if both flags are true. If not, set a timer to change the flag back to its initial state. You can then assign this same callback to listen to both events. That should help you achieve what you want.
13th Dec 2021, 6:20 AM
Gordon
Gordon - avatar
0
Ipang eventlistener's condition I want "click"&&"contextmenu"
12th Dec 2021, 8:07 AM
곽민우
곽민우 - avatar