Overview of SVG.js
SVG.js is a lightweight JavaScript library designed for manipulating and animating SVG. It has no dependencies and aims to provide comprehensive coverage of the SVG specification while maintaining a small footprint.
website·Indexed 33 days ago
https://svgjs.dev/docs/3.2/A lightweight JavaScript library for manipulating and animating SVG. Version 3.2 includes features for creating and manipulating SVG elements, attribute management, animation timelines, and support for Node.js. The ecosystem includes various plugins such as svg.draggable.js, svg.panzoom.js, svg.filter.js, and ngx-svg for Angular 2+.
svg.draggable.js plugin provides functionality to make SVG elements draggable within the browser.# Install via npm (implied by plugin structure)
npm install @svgjs/draggablelast 1 version or > 0.25% or not maintained node versions or not dead. While JavaScript syntax is transpiled, missing browser APIs are not automatically added. Developers must configure their own build's syntax transforms and provide additional polyfills for older target browsers.svg.topoly.js plugin provides functionality to convert an SVG path element into either a polygon or a polyline.svg.topath.js plugin provides functionality to convert any SVG shape element into a path element. This is useful for animations or manipulations that require the flexibility of path data.# Install via npm
npm install svg.topath.jssvg.easing.js plugin provides a wider variety of easing methods for animations within the SVG.js ecosystem. It can be integrated into projects to allow for more complex and natural movement patterns beyond the default easing options.foreignObject() constructor on an SVG.Container allows you to embed elements from non-SVG namespaces (primarily HTML) within an SVG. To ensure HTML elements are created in the correct HTML namespace, pass true as the second parameter to the SVG() function when adding them to the foreign object.var foreignObject = draw.foreignObject(width, height)
// Pass true as second parameter to SVG() to create an element in the html-namespace
foreignObject.add(SVG('<input type="text">', true))The Runner.transform() method supports two interpolation modes and can apply targets absolutely or relatively.
SVG.Matrix for direct component interpolation.// Absolute transform
rect.animate(1000).transform({ rotate: 90, scale: 2 })
// Relative transform (using second argument true)
rect.animate(1000).transform({ translate: [100, 0] }, true)
// Relative transform helpers (shorthand)
rect.animate(1000).translate(100, 0).rotate(90).scale(2)
// Matrix interpolation with affine forced (third argument true)
const target = new SVG.Matrix().rotate(90)
rect.animate(1000).transform(target, false, true)SVG() to allow SVG.js to manage it and provide access to the SVG.js API.var polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon')
var element = SVG(polygon)
element.fill('#f06')dist folder.npm install
npm run build