使用画布模拟图层
我尝试用重叠的 HTML5 画布来模拟图层,但这似乎不起作用。 HTML 中定义的第一个画布将获取所有事件,mousedown、mouseup、mousemove。
http://jsbin.com/ewival/edit#preview
是否可以用canvas模拟layeys ?这样我就可以独立使用图层/画布了?
I tried similating layers with overlapping HTML5 canvas but that doesn't appear to work. The 1st canvas defined in HTML will get all the events, mousedown, mouseup, mousemove.
http://jsbin.com/ewival/edit#preview
Is it possible to simulate layeys with canvas? So that I can work with layers/canvas independently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的办法是始终将 100% 的事件处理程序保留在最顶层的画布上,并让这些事件按顺序考虑每个画布。
因此,只有一个鼠标按下等操作,它将查看您的画布列表,执行相关操作(命中检测等)。假设您的画布直接位于彼此上方,则不会出现坐标问题。
Your best bet is to always keep 100% of the event handlers on the topmost canvas, and have those events consider each canvas in order.
So there will only be one mousedown, etc, and it will look through your list of canvases doing the relevant things (hit detection, etc). Assuming your canvases are directly over each other, there will be no coordinate issues.