SVG.js v3.2
SVG.js v3.2

原始链接: https://svgjs.dev/docs/3.2/

## SVG.js:一个轻量级的 SVG 操作库 SVG.js 是一个快速且小型的 JavaScript 库,旨在创建和动画化可缩放矢量图形 (SVG)。它几乎完全覆盖了 SVG 规范,*无需*任何外部依赖。 主要优点包括**速度**——明显快于许多竞争库,虽然不如纯 JavaScript 快——以及**简洁明了的语法**。与冗长的原生 JavaScript SVG 创建相比,SVG.js 显著减少了代码长度和重复,使开发更轻松、更易读。 例如,使用 SVG.js 创建一个简单的填充正方形只需要两行代码,而使用标准 JavaScript 则需要十行。它也适用于复杂的动画。 SVG.js 是开源的,并采用 MIT 许可证。

## SVG.js v3.2 在 Hacker News 的讨论 最近一则 Hacker News 帖子讨论了 SVG.js 库 (svgjs.dev),版本 3.2。它因其易于开发和代码可读性而受到赞扬——在 SVG 操作方面,它比原生 JavaScript 提供了更简洁的语法。但用户也指出一个显著的性能缺点:据报道,它的速度比直接使用原生 JavaScript 慢 10 倍。 讨论的重点在于考虑到这种速度差异,该库的价值主张。一些人认为,对于开发速度和可维护性比性能更重要的项目,或者在浏览器之外的用例中,它可能是有益的。另一些人指出,原生 JavaScript SVG 创建虽然可能冗长,但效率很高。 对话还扩展到 SVG 操作的 Python 库的推荐,包括 `svgwrite`、`svg.py` 和 `drawsvg`。 几位用户还提到了使用 D3.js 来生成 SVG。
相关文章

原文

The lightweight library for manipulating and animating SVG.

Star

Why choose SVG.js?

SVG.js has no dependencies and aims to be as small as possible while providing close to complete coverage of the SVG spec. If you're not convinced yet, here are a few highlights.

It's speedy.

SVG.js is fast. Obviously not as fast as vanilla js, but many times faster than the competition:

Index:

  • rects: generate 10000 rects
  • fill: generate 10000 rects with fill color
  • gradient: generate 10000 rects with gradient fill

Less is better. Tested on an Intel Core i7-4702MQ @ 2.2GHz.

Easy readable, uncluttered syntax.

Creating and manipulating SVG using JavaScript alone is pretty verbose. For example, just creating a simple pink square requires quite a lot of code:

SVG.js provides a syntax that is concise and easy to read. Doing the same as the vanilla js example above:

// SVG.js
var draw = SVG().addTo('#drawing')
  , rect = draw.rect(100, 100).fill('#f06')

That's just two lines of code instead of ten! And a whole lot less repetition.

Go crazy with animations

There is more...

License

SVG.js is licensed under the terms of the MIT License.

Changelog

Wondering what has changed in the latest releases? Have a look at the change log.

联系我们 contact @ memedata.com