在KineticJS中检测点击阶段,但不检查形状 [英] Detecting a Click on Stage but not on Shape in KineticJS

查看:176
本文介绍了在KineticJS中检测点击阶段,但不检查形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在KineticJS中,如何检测点击事件,其中点击发生在对象/形状之外?

In KineticJS, how do you detect a Click event where the click occurs outside an object/shape?

我试图让一个 Rect 将其规模更改为 2 时,用户点击它,然后返回

I am trying to get a Rect to change its scale to 2 when a user clicks on it, and return back to a scale of 1 when the user clicks anywhere outside it.

JSfiddle: http://jsfiddle.net/ABTAD/8/

管理以检测舞台上的点击,但点击 Rect 也会触发点击处理程序!和 .setScale(1)不做任何事情,而 console.log 打印出来的东西。当在 Rect 而不是空阶段上进行点击时,如何防止点击处理程序触发?

Managed to detect a click on stage, but clicking on the Rect also fires the click handler!!! And somehow the .setScale(1) does not do anything, while console.log printes something out. How can I prevent the click handler from firing when the click is made on the Rect instead of the empty stage?

JS代码检测点击阶段

window.stage.getContainer().addEventListener('click', function(e) {
    $.each(window.layer.get('.box'), function(index, box) {
       box.setScale(1);
       console.log('clicked on stage');
    });
});


推荐答案

您可以使用stage.getContent ()。从那里,你可以像这样添加一个事件处理程序:

you can access the stage content wrapper with stage.getContent(). From there, you can add an event handler like this:

stage.getContent()。addEventListener('click',...); // regular javascript

stage.getContent().addEventListener('click', ...); // regular javascript

$(stage.getContent())。on('click' ...); // jquery

$(stage.getContent()).on('click', ...); // jquery

这篇关于在KineticJS中检测点击阶段,但不检查形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆