I have a canvas which listens for mouse down event… but I wanted to make it more detailed by listening on the buttons and if they were double clicks or not.
I have this:
canvas.addEventListener("mousedown", what_button, false);
Then a function named what_button:
function what_button(e){
//check which button on the mouse
//was it a double click ?
}
Is this possible in JavaScript?
I don’t think that the
'mousedown'event is able to anticipate whether or not a second mouse click will occur. You’ll have to bind to both'click'and'dblclick'and then override the behavior if a double-click occurred…Inside the handler, the
e.buttonproperty tells you which button was clicked:This works for me:
Live demo: http://jsfiddle.net/f73tY/1/
I use a delay value of
200. I have found that (at least on my machine) a value of100does not detect a double-click.