Search code examples
javascriptclickmousekineticjs

KineticJS: Get the mouse button, x and y from the 'click' event on a Circle


Using KineticJS, I created a Circle: using the following line:

var circle = new Kinetic.Circle({...});

Then, I started listening to the 'click' event this way:

circle.on("click", function(evt) {
  // Hope to get the mouse button, x and y here...
});

Using the evt object above, I hope to get the mouse button that was used to click, and the X and Y of the click location. I inspected the evt object, and could not find any of these.

I did get the target node, and the event type from this 'evt' object though.

Am I missing anything? May be another argument to the click handler?

I will post a SSCCE if this information is not enough.

Any response is appreciated!


Solution

  • In the latest KineticJS version (5.1.0), you can get the position by accessing evt.evt.clientX and evt.evt.clientY.

    Regarding the detection of which mouse button was clicked, you could take a look at this approach with jquery for cross-browser support