gpt4 book ai didi

javascript - 如何从PaperJS中的CompoundPath中识别鼠标事件的目标子路径?

转载 作者:行者123 更新时间:2023-12-02 22:33:28 24 4
gpt4 key购买 nike

我将“mousedown”事件监听器添加到CompoundPath(而不是它的子级)。但我需要知道事件发生在哪个 child 身上。事件对象的“target”属性返回CompoundPath。那么,解决办法是什么?

最佳答案

解决方案主要取决于您的具体用例。
但解决此问题的一种通用方法可能是在每个 CompoundPath 子项的事件点处进行 HitTest ,并推断出哪个子项触发了该事件。
这是sketch演示解决方案。

const circle1 = new Path.Circle({
center: view.center - 50,
radius: 50
});

const circle2 = new Path.Circle({
center: view.center + 50,
radius: 50
});

const compoundPath = new CompoundPath({
children: [circle1, circle2],
fillColor: 'orange',
onMouseDown: event => {
if (circle1.hitTest(event.point)) {
alert('circle 1 clicked');
} else if (circle2.hitTest(event.point)) {
alert('circle 2 clicked');
}
}
});

关于javascript - 如何从PaperJS中的CompoundPath中识别鼠标事件的目标子路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58816534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com