Convert Figma logo to code with AI

merri-ment logolazy-line-painter

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

1,962
325
1,962
16

Top Related Projects

15,183

JavaScript library to make drawing animation on SVG

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

🎉 performant confetti animation in the browser

49,575

JavaScript animation engine

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/

Quick Overview

The lazy-line-painter is a JavaScript library that provides a simple and efficient way to create animated SVG line drawings. It allows developers to create complex line animations with minimal code, making it a useful tool for creating interactive web experiences, presentations, and data visualizations.

Pros

  • Simplicity: The library has a straightforward API, making it easy to integrate into existing projects.
  • Flexibility: The library supports a wide range of customization options, allowing developers to fine-tune the appearance and behavior of the line animations.
  • Performance: The library uses efficient rendering techniques to ensure smooth animations, even on low-powered devices.
  • Cross-browser Compatibility: The library is designed to work across a wide range of modern web browsers, ensuring consistent performance and appearance.

Cons

  • Limited Documentation: The project's documentation could be more comprehensive, which may make it challenging for new users to get started.
  • Dependency on SVG: The library is designed to work with SVG, which may not be the best choice for all use cases, particularly on older browsers or in performance-critical applications.
  • Lack of Community Support: The project does not have a large, active community, which may limit the availability of third-party plugins or extensions.
  • Potential Performance Issues: While the library is designed to be efficient, complex animations may still cause performance issues on some devices or in certain scenarios.

Code Examples

Here are a few examples of how to use the lazy-line-painter library:

  1. Basic Line Animation:
const painter = new LazyLinePainter('#my-svg', {
  svgData: 'M10,90 C40,10 65,10 90,90',
  strokeWidth: 2,
  strokeColor: '#000',
  strokeDuration: 2000,
  ease: 'easeLinear',
  delay: 0
});

painter.paint();
  1. Chained Animations:
const painter = new LazyLinePainter('#my-svg', {
  svgData: [
    'M10,90 C40,10 65,10 90,90',
    'M10,10 L90,90',
    'M10,90 L90,10'
  ],
  strokeWidth: 2,
  strokeColor: '#000',
  strokeDuration: 2000,
  ease: 'easeLinear',
  delay: 500
});

painter.paint();
  1. Customizing Appearance:
const painter = new LazyLinePainter('#my-svg', {
  svgData: 'M10,90 C40,10 65,10 90,90',
  strokeWidth: 4,
  strokeColor: '#ff0000',
  strokeDuration: 3000,
  ease: 'easeInOutQuad',
  delay: 1000,
  onComplete: () => console.log('Animation complete!')
});

painter.paint();

Getting Started

To get started with the lazy-line-painter library, follow these steps:

  1. Install the library using npm or yarn:
npm install lazy-line-painter
  1. Import the library in your JavaScript file:
import LazyLinePainter from 'lazy-line-painter';
  1. Create a new instance of the LazyLinePainter class, passing in the target SVG element and the desired configuration options:
const painter = new LazyLinePainter('#my-svg', {
  svgData: 'M10,90 C40,10 65,10 90,90',
  strokeWidth: 2,
  strokeColor: '#000',
  strokeDuration: 2000,
  ease: 'easeLinear',
  delay: 0
});
  1. Call the paint() method to start the animation:
painter.paint();

That's it! You can now use the lazy-line-painter library to create dynamic line animations in your web applications.

Competitor Comparisons

15,183

JavaScript library to make drawing animation on SVG

Pros of Vivus

  • Vivus provides a more comprehensive set of features, including support for various SVG animation types (delayed, sync, oneByOne, scenario, scenario-sync).
  • Vivus has a larger community and more active development, with more contributors and a higher number of issues and pull requests.
  • Vivus offers more customization options, allowing you to fine-tune the animation behavior and appearance.

Cons of Vivus

  • Vivus has a larger file size compared to Lazy Line Painter, which may impact performance in some cases.
  • Vivus has a steeper learning curve, with more configuration options and a more complex API.
  • Vivus may have a higher overhead for simple use cases, where Lazy Line Painter might be a more lightweight and straightforward solution.

Code Comparison

Lazy Line Painter:

var lazyLinePainter = new LazyLinePainter('#my-svg', {
  strokeWidth: 3,
  strokeColor: '#000',
  strokeDashArray: '100',
  strokeDashOffset: '100',
  onDraw: function() {
    console.log('Drawing complete!');
  }
});

Vivus:

new Vivus('my-svg', {
  type: 'delayed',
  duration: 200,
  delay: 120,
  onReady: function(myVivus) {
    myVivus.play();
  }
});

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

Pros of Lazy Line Painter

  • Provides a simple and intuitive API for creating animated line drawings
  • Supports a wide range of customization options, such as line color, thickness, and animation duration
  • Includes a comprehensive set of examples and documentation to help users get started

Cons of Lazy Line Painter

  • May not be as feature-rich as some other SVG animation libraries
  • Limited support for complex or dynamic line paths
  • Potential performance issues with large or complex drawings

Code Comparison

Here's a brief comparison of the code for creating a simple line animation in both repositories:

Lazy Line Painter:

const painter = new LazyLinePainter('#my-element', {
  strokeWidth: 2,
  strokeColor: '#000',
  strokeDashoffset: 100,
  onComplete: () => console.log('Animation complete')
});

painter.paint();

Lazy Line Painter>:

const painter = new LazyLinePainter('#my-element', {
  strokeWidth: 2,
  strokeColor: '#000',
  strokeDashoffset: 100,
  onComplete: () => console.log('Animation complete')
});

painter.paint();

As you can see, the code is nearly identical between the two repositories, demonstrating the consistency and stability of the Lazy Line Painter library.

🎉 performant confetti animation in the browser

Pros of canvas-confetti

  • Lightweight: canvas-confetti is a lightweight library, weighing in at around 3KB gzipped, making it a good choice for performance-sensitive applications.
  • Customizable: The library provides a range of options for customizing the confetti, including color, size, and animation.
  • Cross-browser compatibility: canvas-confetti is designed to work across a wide range of modern browsers, ensuring a consistent experience for users.

Cons of canvas-confetti

  • Limited functionality: Compared to Lazy Line Painter, canvas-confetti is focused solely on creating confetti animations, and does not provide the same level of flexibility for creating custom line animations.
  • Dependency on canvas: Since canvas-confetti relies on the HTML5 canvas element, it may not be suitable for applications that require more complex or interactive graphics.

Code Comparison

Here's a brief comparison of the code for creating a simple confetti animation using canvas-confetti and a line animation using Lazy Line Painter:

canvas-confetti:

import confetti from 'canvas-confetti';

confetti({
  particleCount: 100,
  spread: 70,
  origin: { y: 0.6 }
});

Lazy Line Painter:

import LazyLinePainter from 'lazy-line-painter';

const painter = new LazyLinePainter('#my-element', {
  strokeWidth: 2,
  strokeColor: '#000',
  ease: 'easeInOutQuad',
  delay: 0,
  duration: 2000
});

painter.paint();
49,575

JavaScript animation engine

Pros of Anime

  • Extensive Animation Features: Anime provides a wide range of animation features, including timeline-based animations, easing functions, and support for SVG, DOM, and canvas elements.
  • Flexible and Customizable: The library offers a high degree of customization, allowing developers to create complex and unique animations with ease.
  • Extensive Documentation: Anime has comprehensive documentation, making it easier for developers to understand and use the library effectively.

Cons of Anime

  • Larger File Size: Anime has a larger file size compared to Lazy Line Painter, which may impact the performance of web applications, especially on slower connections.
  • Steeper Learning Curve: Anime's extensive features and customization options can make it more challenging for beginners to get started, compared to the simpler Lazy Line Painter.

Code Comparison

Lazy Line Painter:

const lazyLinePainter = new LazyLinePainter({
  svg: '#lazy-line-svg',
  path: '#lazy-line-path',
  strokeWidth: 2,
  strokeColor: '#000',
  ease: 'easeInOutCubic',
  delay: 0,
  duration: 3000
});

lazyLinePainter.paint();

Anime:

anime({
  targets: '#anime-path',
  d: [
    { value: 'M100,100 L300,100 L200,300z' },
    { value: 'M100,100 C100,300 400,300 400,100' }
  ],
  duration: 3000,
  loop: true,
  direction: 'alternate',
  easing: 'linear'
});

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/

Pros of Lottie-web

  • Lottie-web is a powerful and feature-rich library for rendering After Effects animations on the web, providing a smooth and efficient way to incorporate animations into web applications.
  • The library is actively maintained by Airbnb and has a large and supportive community, ensuring ongoing development and bug fixes.
  • Lottie-web offers a wide range of customization options, allowing developers to fine-tune the appearance and behavior of the animations to fit their specific needs.

Cons of Lottie-web

  • Lottie-web can be more complex to set up and integrate into a project compared to Lazy Line Painter, as it requires additional configuration and setup steps.
  • The library's file size can be larger than Lazy Line Painter, which may impact the initial load time of a web page, especially on slower connections.

Code Comparison

Lazy Line Painter:

var lazyLinePainter = new LazyLinePainter({
  selector: '#lazy-line',
  strokeWidth: 2,
  strokeColor: '#000',
  ease: 'easeOutQuint',
  delay: 0,
  duration: 3000
});

Lottie-web:

var animation = lottie.loadAnimation({
  container: document.getElementById('lottie'),
  renderer: 'svg',
  loop: true,
  autoplay: true,
  path: 'path/to/animation.json'
});

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Lazy Line Painter

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 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.
A free Online Editor developed specifically for SVG path animation.


NPM
pnpm i lazy-line-painter
CDN
<script src="https://cdn.jsdelivr.net/npm/lazy-line-painter@2.0.3/lib/lazy-line-painter-2.0.3.min.js"></script>
DOWNLOAD
<script src="./libs/lazylinepainter-2.0.3.js"></script>



Quick Start

The most basic, no-frills implementation;

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


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.

<path 

  // style 
  data-llp-stroke-width="10"
  data-llp-stroke-color="#000000"
  data-llp-stroke-opacity="0.5" 
  data-llp-stroke-cap="rounded" 
  data-llp-stroke-join="mitre" 

  // animation
  data-llp-stroke-dash="[2,2]" 
  data-llp-duration="200" // (ms)
  data-llp-delay="200" // delay offset from start of timeline (ms)
  data-llp-reverse="true" (default = "false") 
  data-llp-ease="easeInOutQuad" (default = 'easeLinear') 

  />



API Reference

Methods

Paint - accepts optional playback arguments - reverse, ease, delay

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;

myAnimation.erase();

Pause

myAnimation.pause();

Resume

myAnimation.resume();

Progress

// set - [0 - 1]
myAnimation.progress(value);

// get
const progress = myAnimation.progress();
console.log(progress);

Destroy - destroys svg & lazyline instance

myAnimation.destroy();



Events

Handle events across entire animation
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.

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.

myAnimation.on("start:id", (event) => {});
myAnimation.on("update:id", (event) => {});
myAnimation.on("complete:id", (event) => {});
Timeline playback events
myAnimation.on("pause", () => {});
myAnimation.on("resume", () => {});
myAnimation.on("erase", () => {});



Examples



Changelog

Refer to Release notes for entire Changelog



Author

https://merriment.info/

NPM DownloadsLast 30 Days