更改事件类型
是否可以更改 JavaScript 中事件的类型
?
在这种情况下,我在画布上使用 jQuery 触发事件,但在呈现此画布的特定元素上触发事件,例如绘制的形状或图像。
mousemoveevent ---> [canvas] -> [find element] ---> mousemoveoverelementevent
基本上我在整个画布上捕获 onmousemove 事件:
$('canvas').bind('mousemove'........
但是画布内不存在 DOM,所以我希望它转换(在过程中稍后跟进)到:
$('canvas').bind('mousemoveOverElement'........
$('canvas').bind('mouseenterOnElement'........
$('canvas').bind('mouseleaveOnElement'........
然后分配类似
e.element = 'imageAtACertainPositionInTheCanvas'
I 更喜欢传递修改的事件而不是分配新的回调。
Is it possible to change the type
of an event in JavaScript?
in this scenario I am triggering events with jQuery on a canvas, but on specific elements in rendered this canvas, like drawn shapes or images.
mousemoveevent ---> [canvas] -> [find element] ---> mousemoveoverelementevent
Basically I catch the onmousemove event over the complete canvas with:
$('canvas').bind('mousemove'........
but the DOM does not exist within the canvas so I want it to transform (to chatch up later in the process) to:
$('canvas').bind('mousemoveOverElement'........
$('canvas').bind('mouseenterOnElement'........
$('canvas').bind('mouseleaveOnElement'........
and then assign something like
e.element = 'imageAtACertainPositionInTheCanvas'
I prefer to pass the modified event instead of assigning a new callback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能想阅读Sprite 和 Canvas 的问题及其相对较差的性能。
You might want to read the issue of Sprite and Canvas and their relative bad performances too.
我没听懂你说的,也许你能说得更具体一些。
我知道您可以更改自定义事件的类型。
无论如何,这个链接可以帮助你:
DOM Level 3 Events
nsIDOMWindowUtils
I didn't understand what you said, maybe you could be more specific.
I know that you can change the type of a custom event.
Anyway this links can help you:
DOM Level 3 Events
nsIDOMWindowUtils
[示例]
[Example]
我相信您正在寻找的答案是“jQuery 自定义事件”。 jQuery 自定义事件使您能够命名和组织事件处理程序;然后,这些事件处理程序可以由
$(el).trigger('the_event')
触发。只需谷歌搜索该词的用法和示例即可。我不认为它可以覆盖事件对象,就像您建议的
e.element
一样。您可能需要重新考虑流程以适应它。(并不是说这个答案值得200声望,但无论如何,希望它对您找到方法有帮助。)
I believe the answer you are seeking for is 'jQuery custom event'. jQuery custom event provides you abilities to name and organize your event handlers; these event handlers can then be triggered by
$(el).trigger('the_event')
. Just google for the word for usage and example.I don't it could overwrite the event object, like
e.element
you suggested though. You may need to rethink the flow to fit it.(Not the that this answer worth 200 reputation but here it is anyway, hope that it's helpful for you to find a way.)