Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/camoconnell/lazy-line-painter

Lazy Line Painter - A Modern JS library for SVG path animation
https://github.com/camoconnell/lazy-line-painter

animation animation-library drawing javascript js lightweight path-animation responsive svg

Last synced: about 1 month ago
JSON representation

Lazy Line Painter - A Modern JS library for SVG path animation

Awesome Lists containing this project

README

        

![Lazy Line Painter](https://lazylinepainter.com/banner.png)


Bundle Size
GitHub Release
License
npm Version


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/)