HTML5 Canvas VS SVG / VML? [英] HTML5 Canvas vs SVG/VML?

查看:171
本文介绍了HTML5 Canvas VS 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.

推荐答案

HTML5 Canvas只是位图的绘图表面。你设置了一个绘图(用颜色和线条粗细说),画出那个东西,然后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.

另一方面,您创建的每个SVG / VML元素都是DOM中的真正元素。默认情况下,这允许你更好地跟踪你创建的元素,并使处理事情,如鼠标事件更容易默认情况下。

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更适合更快的事情,重磅的位图操作(如动画),但如果你想要大量的互动,将需要更多的代码。

Canvas would be better for faster things and heavy bitmap manipulation (like animation), but will take more code if you want lots of interactivity.

这篇关于HTML5 Canvas VS SVG / VML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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