admin管理员组

文章数量:1395904

)

I have a question about the KonvaJS.

I am trying to figure out how to catch the right click mouse event on a shape.

There are already some events for this kind of "event catching" but it seems to be that they are not for the shapes/groups.

So, what I've already tried:

group.addEventListener('contextmenu', function() {
    alert("test");
});

group.on('contextmenu', function(){
    alert("test");
});

group.on('contentContextmenu', function(){
    alert("test");
});

All three of them are not working

The only thing what is working fine

stage.on('contentContextmenu', function(e) {
  e.evt.preventDefault();
  console.log(e);
});

Is there any other events present in the framework?

Maybe you can help me =)

Thank You

)

I have a question about the KonvaJS.

I am trying to figure out how to catch the right click mouse event on a shape.

There are already some events for this kind of "event catching" but it seems to be that they are not for the shapes/groups.

So, what I've already tried:

group.addEventListener('contextmenu', function() {
    alert("test");
});

group.on('contextmenu', function(){
    alert("test");
});

group.on('contentContextmenu', function(){
    alert("test");
});

All three of them are not working

The only thing what is working fine

stage.on('contentContextmenu', function(e) {
  e.evt.preventDefault();
  console.log(e);
});

Is there any other events present in the framework?

Maybe you can help me =)

Thank You

Share Improve this question asked Feb 17, 2018 at 2:14 XearoxXearox 492 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8
// do not show context menu on right click
stage.on('contextmenu', (e) => {
  e.evt.preventDefault();
});


// do something else on right click
circle.on('click', (e) => {
  if (e.evt.button === 2) {
    alert('right click')
  }
});

Demo: https://jsbin./junilaboqo/1/edit?js,output

本文标签: javascriptIs it possible to catch the right click event on a shapegroup in KonvaJSStack Overflow