Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/merri-ment/lazy-line-painter
Lazy Line Painter - A Modern JS library for SVG path animation
https://github.com/merri-ment/lazy-line-painter
animation animation-library drawing javascript js lightweight path-animation responsive svg
Last synced: 7 days ago
JSON representation
Lazy Line Painter - A Modern JS library for SVG path animation
- Host: GitHub
- URL: https://github.com/merri-ment/lazy-line-painter
- Owner: merri-ment
- License: mit
- Created: 2013-01-19T16:06:07.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2023-12-12T05:15:03.000Z (about 1 year ago)
- Last Synced: 2024-10-29T15:33:49.787Z (3 months ago)
- Topics: animation, animation-library, drawing, javascript, js, lightweight, path-animation, responsive, svg
- Language: JavaScript
- Homepage: https://lazylinepainter.com
- Size: 1.24 MB
- Stars: 1,968
- Watchers: 72
- Forks: 325
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
![Lazy Line Painter](https://lazylinepainter.com/banner.png)
Lazy Line Painter
lazylinepainter.com
A Modern JS library for SVG path animation
Getting Started | Documentation | Examples | Lazy Line Composer
# Getting Started
![Lazy Line Painter](https://lazylinepainter.com/drag_drop.jpg)
_Lazy Line Painter can be setup with minimal effort as per the Quick Start instructions.
However if a GUI is more your thing, be sure to use the [Lazy Line Composer](https://lazylinepainter.com/#composer).
A free Online Editor developed specifically for SVG path animation._
##### [NPM](https://www.npmjs.com/package/lazy-line-painter)
```js
pnpm i lazy-line-painter
```##### [CDN](https://www.jsdelivr.com/package/npm/lazy-line-painter)
```html
```
##### [DOWNLOAD](https://github.com/merri-ment/lazy-line-painter/releases)
```html
```
### Quick Start
The most basic, no-frills implementation;
```js
// import LazyLinePainter
import LazyLinePainter from "lazy-line-painter";// select your svg
const el = document.querySelector("#my-svg");// initialise & configure LazyLinePainter
const myAnimation = new LazyLinePainter(el, { strokeWidth: 10 });// paint! :)
myAnimation.paint();
```
# Documentation
### Configuration
##### Configure on initialisation
On initialise you can pass lazylinepainter a config object as an argument containing the attritubes you wish to alter across the entire svg.
All config properties are optional.
Style attributes set in the config will override css styles.```js
const config = {
// style properties
'strokeWidth' // Adjust width of stroke
'strokeColor' // Adjust stroke color
'strokeCap' // Adjust stroke cap - butt | round | square
'strokeJoin' // Adjust stroke join - miter | round | bevel
'strokeOpacity' // Adjust stroke opacity 0 - 1
'strokeDash' // Adjust stroke dash - '5, 5'// animation properties
'delay' // Delay before animation starts
'reverse' // reverse playback
'ease' // penner easing - easeExpoOut / easeExpoInOut / easeExpoIn etc
'repeat' // number of additional plays, -1 for loop
}const svg = document.querySelector('#my-svg')
const myAnimation = new LazyLinePainter(svg, config)```
##### Configure individual paths
Data attributes can be used to configure style & animation properties on individual paths in the SVG.
Data attributes will override both css styles & initialisation config style attributes.```html
```
### API Reference
#### Methods
**Paint** - accepts optional playback arguments - reverse, ease, delay
```js
const reverse = true;
const ease = "easeExpoOut";
const delay = 200;
myAnimation.paint({ reverse, ease, delay });
```**Erase** - paint can still be called on the element after it has been erased;
```js
myAnimation.erase();
```**Pause**
```js
myAnimation.pause();
```**Resume**
```js
myAnimation.resume();
```**Progress**
```js
// set - [0 - 1]
myAnimation.progress(value);// get
const progress = myAnimation.progress();
console.log(progress);
```**Destroy** - destroys svg & lazyline instance
```js
myAnimation.destroy();
```
#### Events
##### Handle events across entire animation
```js
myAnimation.on("start", () => {});
myAnimation.on("update", () => {});
myAnimation.on("complete", () => {});
```##### Handle all events
Called for each shape animated within the svg.
event argument contains shape properties.```js
myAnimation.on('start:all', (event) => {});
myAnimation.on('update:all', (event) => { console.log(event.progress); // [0-1] });
myAnimation.on('complete:all', (event) => {});
```##### Handle targeted events.
Listen to events on specific shapes by adding the shape-id after the colon.
event argument contains shape properties.```js
myAnimation.on("start:id", (event) => {});
myAnimation.on("update:id", (event) => {});
myAnimation.on("complete:id", (event) => {});
```##### Timeline playback events
```js
myAnimation.on("pause", () => {});
myAnimation.on("resume", () => {});
myAnimation.on("erase", () => {});
```
# [Examples](https://codepen.io/collection/DLLeRb/)
- [Hello World Example](https://codepen.io/camoconnell/pen/zeqgWB)
- [Event Example](https://codepen.io/camoconnell/pen/vvKWzP)
- [Set Example](https://codepen.io/camoconnell/pen/GPYGvd)
- [Playback Options](https://codepen.io/camoconnell/pen/wRYELj)
## Changelog
_Refer to [Release notes](https://github.com/merri-ment/lazy-line-painter/releases) for entire Changelog_
## Author
[https://merriment.info/](https://merriment.info/)