HTML5 Canvas 与 SVG/VML?
请告诉我您对 HTML5 Canvas 与 SVG/VML 有何看法?比较一下优点和缺点。
谢谢你!!!
Please tell me what do you think about HTML5 Canvas vs SVG/VML? Give me pros and cons within comparison.
Thank you!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTML5 Canvas 只是位图的绘图表面。你设置了一个绘图(比如用颜色和线条粗细),绘制那个东西,然后画布不知道那个东西:它不知道它在哪里或它是什么,它只是像素。如果您想绘制矩形并让它们四处移动或可供选择,那么您必须从头开始编写所有这些内容,包括记住您绘制它们的代码。
另一方面,您创建的每个 SVG/VML 元素都是 DOM 中的真实元素。默认情况下,这允许您更好地跟踪您创建的元素,并使处理鼠标事件等默认情况下更容易。
Canvas 更适合更快的操作和繁重的位图操作(如动画),但如果您想要大量的交互性,则需要更多的代码。
HTML5 Canvas is simply a drawing surface for a bit map. You set up a draw (Say with a color and line thickness) , draw that thing, and then the Canvas has no knowledge of that thing: It doesn't know where it is or what it is, it's just pixels. If you want to draw rectangles and have them move around or be selectable then you have to code all of that from scratch, including the code to remember that you drew them.
On the other hand, every SVG/VML element you create is a real element in the DOM. By default this allows you to keep much better track of the elements you create and makes dealing with things like mouse events easier by default.
Canvas would be better for faster things and heavy bitmap manipulation (like animation), but will take more code if you want lots of interactivity.