有 SVG 的跨浏览器解决方案吗?
我知道 Raphael.js 使用 svg,并且它完全跨浏览器:它甚至可以在 ie6 上运行!所以我想一定有一些 js 修复允许在每个浏览器中使用 svg,对吧?我不需要像 Raphael 这样的完整图形和动画库,只需要 IE 等中的 SV 支持。
我刚刚读到有关 SVGweb 的内容,其中 Google 参与了开发,但显然它使用 Flash,因此它不是跨浏览器安全的。
I know Raphael.js uses svg, and its totally crossbrowser: it even works on ie6! So I guess there must be some js fix that allows to use svg in every browser, right? I dont need a whole graphics and animation library like Raphael, just SV support in IE and the like.
I was just reading about SVGweb, in which development Google was involved, but apparently it uses Flash, so its not cross browser safe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Raphael 有一个用于 IE 的绘图后端,它使用 VML DOM,还有一个用于支持 SVG 的浏览器的后端,它使用 SVG DOM。然后,它有一个公开统一绘图 API 的外观,并在运行时加载适当的后端,该后端将对统一绘图 API 的调用委托给适当的浏览器 API(SVG 或 VML DOM)。
这是 js 库中的常见策略。例如,dojox.gfx 中也采用了此策略。看,这是 SVG 适配器: http://svn.dojotoolkit.org/ src/dojox/trunk/gfx/svg.js 这是 VML 适配器:http://svn.dojotoolkit.org/src/dojox/trunk/gfx/vml .js
虽然我自己没有尝试过,但您可能会考虑的另一个库是 Ample SDK,其工作方式与 SVG Web 类似,开发人员针对常规 SVG DOM API 进行编程,而不是 JavaScript 库公开的特定 API。与 SVG Web 一样,为了实现此目的,它在内部使用了 Shadow DOM。然而,它与 SVG Web 不同,它不使用 Flash,而是委托给 IE 内部的 VML。
Raphael has a drawing backend for IE, which uses VML DOM, and a backend for SVG-enabled browsers, which uses SVG DOM. It then has a facade which exposes a uniform drawing API, and at runtime, it loads the appropriate backend, which delegates calls to the uniform drawing API to the appropriate browser API (either SVG or VML DOM).
This is a common strategy in js libraries. For example, this strategy is also employed in dojox.gfx. See, here's the SVG adapter: http://svn.dojotoolkit.org/src/dojox/trunk/gfx/svg.js And here's the VML adapter: http://svn.dojotoolkit.org/src/dojox/trunk/gfx/vml.js
Although I haven't tried it myself, another library you might look into is the Ample SDK, which works similarly to SVG Web, in that the developer programs against the regular SVG DOM API, as opposed to a specific API exposed by a JavaScript library. Like SVG Web, to accomplish this, it uses a shadow DOM internally. It is, however, different from SVG Web, in that it does not use Flash, but instead delegates to VML internally in IE.
我同时使用了 svgweb 和 Raphael。我发现当在 DOM 中添加和删除大量元素时(即使使用 suspendRedraw ),svgweb 的性能很糟糕。 Raphael 对整个 SVG 规范的支持不完整。
我发现唯一完全足够的解决方案是使用 Google Chrome Frame 来支持 SVG。它非常无缝,甚至还修补了有缺陷的 javascript!
它适用于 IE6+ 和所有其他本身不支持 SVG 的浏览器。
http://code.google.com/chrome/chromeframe/
I used both svgweb and Raphael. I found svgweb has terrible performance when there is a lot of adding and removing elements to/from the DOM ( even with suspendRedraw ). Raphael had incomplete support for the whole SVG spec.
The only solution I found to be completely adequate is to use Google Chrome Frame to support SVG. It's soo seamless and it even patches the buggy javascript!
It works in IE6+ and every other browser that doesn't support SVG natively.
http://code.google.com/chrome/chromeframe/