画布元素具有“改变”事件? [英] Does canvas element have "change" event?

查看:127
本文介绍了画布元素具有“改变”事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有方法将事件处理程序附加到 canvas 元素的更改中?

Is there a way to attach event handler to a change of a canvas element? I need to fire a function whenever something draws anything on it.

推荐答案

不, canvas 元素不提供任何事件,它只是一个简单的位图。

No, the canvas element does not provide any events, it's just a plain bitmap.

如果你真的想这样做,劫持所有的调用< $ c> context 在你的事件中创建,然后调用原来的函数(你以前复制过)。

If you really want to do this, hijack all the calls on a context built in your events and then call the original function (which you have copied previously).



不要执行上述操作,它会很慢且难以维护。相反,改变你的应用程序的设计,你可以做自定义绘图函数,它将抽象画布,并把事件的东西放在那里。

My advice:
Do not do the above, it will be slow and hard to maintain. Instead change the design of your application, you could, for one, make custom drawing functions which will abstract the canvas and put in the event stuff there.

在进行大量绘图时, context。* 调用(因此更清晰的代码)的附加好处。

This would also have the added benefit of less context.* calls (therefore cleaner code) when doing a lot of drawing.

这篇关于画布元素具有“改变”事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆