重叠的活动区域
我在画布内有一个方形组件,单击该组件时会显示发光效果 - 指示选择 - 当单击其他地方时,此效果将被删除 - 指示取消选择 问题是画布总是调度“取消选择”事件,即使鼠标位于正方形上方也是如此。 我通过定义一个环境函数来解决这个问题,该函数从父级的“可点击”区域中删除子级的宽度和高度。
有没有更好的方法来告诉画布仅在不超过孩子的情况下调度他的事件?
I got a square component inside a canvas which when clicked shows a glow effect-indicating selection-while clicking somewhere else this effect is removed-indicating deselection
The problem is that the canvas always dispatches the "deselect" event, even if the mouse if over the square.
I worked around this by defining a circumstantial function which removes the child's width,height from the parent's "clickable" area.
Is there a better way to tell the canvas to dispatch his event only if not over the child ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有任何代码很难判断,但我的猜测是,您应该停止在方形组件的侦听器中传播单击事件:
event.stopPropagation();
这样,舞台就不会收到点击方块的通知,也不会发送您的“取消选择”事件。
Hard to tell without any code, but my guess is, you should stop propagation of the click event in the listener for the square component:
event.stopPropagation();
That way, the stage will not be notified of the click on the square and may not send your "deselect" event.