在上面有画布的 Div 之间级联鼠标事件?
那么有没有一种方法可以让我将画布覆盖在相同大小的 div 上,并且让 div 和画布都有各自的 mouseevent 处理程序来处理 mouseclick、mouseover 和 mousemove 事件,尽管画布位于顶部它的?如果是这样,我该如何实现这一目标?
So is there a way for me to overlay a canvas over a div of the same size, and have the both the div and canvas each with their own respective mouseevent handlers to process the mouseclick, mouseover, and mousemove events despite the canvas being on top of it? If so, how do I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
作为
的子级,即
。画布上发生的事件会冒泡到div,你可以处理它们两次。
Put the
<canvas>
as a child of the<div>
, i.e.<div><canvas></canvas></div>
. The events occurring on the canvas will bubble to the div, and you can handle them twice.仅让一种方法调用另一种方法有什么问题吗?
http://jsfiddle.net/ZCuL6/9/
或者如果它们大小相同并且您始终如果希望立即调用它们,也许您应该只为所有鼠标事件使用一种方法,并且始终让这些方法存在于分层的最顶层对象上。
Whats wrong with just having one method call the other?
http://jsfiddle.net/ZCuL6/9/
Or if they are the same size and you always want them called at once, perhaps you should simply have one method for all mouse events, and always have those methods exist on the top-most object of your layering.