Table of Contents
Library 1: Vivus
Library 2: Walkway.js
Library 3: Lazy Line Painter
Library 4: Framer Motion (React-specific)
Home Web Front-end CSS Tutorial Libraries for SVG Drawing Animations

Libraries for SVG Drawing Animations

Mar 31, 2025 pm 02:02 PM

Libraries for SVG Drawing Animations

Animating SVG paths to mimic a drawing effect remains a popular technique, initially popularized by Jake Archibald in 2013. This article explores four JavaScript libraries simplifying this process, particularly beneficial for complex animations involving multiple SVGs and paths.

Previously, Chris Coyier detailed the underlying mechanics using CSS stroke-dasharray and stroke-dashoffset. However, these libraries offer a more concise approach. We'll use a castle SVG from svgrepo (converted to code format via Figma's "Copy as SVG" function) for demonstration. To prepare the SVG, ensure paths have fill="none", a defined stroke (e.g., #B2441D), and stroke-width (e.g., 2px). We'll also group paths by color and assign class names:

  • #695A69: color-1
  • #B2441D: color-2
  • #DFDOC6: color-3
  • #C8B2A8: color-4
  • #DE582A: color-5
  • #AO8A8A: color-6

The animation will first draw the outline, then fill with the respective colors. Here's a simplified SVG snippet:

<svg fill="none" height="480" viewbox="0 0 480 480" width="480" xmlns="http://www.w3.org/2000/svg">
  <path d="..." stroke="#B2441D" stroke-width="2px" class="color-2"></path>
  <path d="..." stroke="#B2441D" stroke-width="2px" class="color-2"></path>
  <!-- ... more paths ... -->
</svg>
Copy after login

Let's examine the libraries:

Library 1: Vivus

Vivus is a lightweight library (no dependencies) for animating SVG drawings. Using a CDN:

<script src="https://cdn.jsdelivr.net/npm/vivus@latest/dist/vivus.min.js"></script>
Copy after login

Create a Vivus instance:

new Vivus('svg-castle', { duration: 200, type: 'oneByOne' });
Copy after login

A callback function fills paths with color:

function fillPath(classname, color) {
  document.querySelectorAll(`#svg-castle .${classname}`).forEach(path => path.style.fill = color);
}

function after() {
  fillPath('color-1', '#695a69');
  // ... fill other colors ...
}
Copy after login

Library 2: Walkway.js

Walkway is another lightweight library for animating SVG paths, lines, and polygons. Using a CDN:

<script src="https://cdn.jsdelivr.net/npm/walkway@latest/dist/walkway.min.js"></script>
Copy after login

Create a Walkway instance and draw:

const svg = new Walkway({ selector: '#svg-castle', duration: 3000 });
svg.draw(after); // Using the same 'after' function from Vivus example
Copy after login

Library 3: Lazy Line Painter

Lazy Line Painter offers a modern approach with minimal setup. Using a CDN:

<script src="https://cdn.jsdelivr.net/npm/lazy-line-painter@latest/dist/lazy-line-painter.min.js"></script>
Copy after login

Initialize and paint, using an event listener for the complete:all event:

let myAnimation = new LazyLinePainter(document.querySelector('#svg-castle'), { strokeDash: '2, 2' });
myAnimation.on('complete:all', after);
myAnimation.paint();
Copy after login

Library 4: Framer Motion (React-specific)

Framer Motion is a powerful React animation library. It requires installation (npm install framer-motion) and uses the <motion.path></motion.path> component. While effective for simpler SVGs, it's less efficient for complex SVGs with numerous paths due to the repetitive nature of converting each path.

Conclusion:

These libraries offer streamlined solutions for creating hand-drawn SVG animation effects, avoiding the complexities of a purely CSS-based approach which would require extensive code repetition for multiple paths. The choice depends on project needs and complexity; for very complex SVGs, Vivus or Walkway might be more suitable than Framer Motion.

The above is the detailed content of Libraries for SVG Drawing Animations. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

A Comparison of Static Form Providers A Comparison of Static Form Providers Apr 16, 2025 am 11:20 AM

Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

The Deal with the Section Element The Deal with the Section Element Apr 12, 2025 am 11:39 AM

Two articles published the exact same day:

Weekly Platform News: HTML Loading Attribute, the Main ARIA Specifications, and Moving from iFrame to Shadow DOM Weekly Platform News: HTML Loading Attribute, the Main ARIA Specifications, and Moving from iFrame to Shadow DOM Apr 17, 2025 am 10:55 AM

In this week&#039;s roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

Some Hands-On with the HTML Dialog Element Some Hands-On with the HTML Dialog Element Apr 16, 2025 am 11:33 AM

This is me looking at the HTML element for the first time. I&#039;ve been aware of it for a while, but haven&#039;t taken it for a spin yet. It has some pretty cool and

Multi-Thumb Sliders: General Case Multi-Thumb Sliders: General Case Apr 12, 2025 am 10:52 AM

The first part of this two-part series detailed how we can get a two-thumb slider. Now we&#039;ll look at a general multi-thumb case, but with a different and

How We Tagged Google Fonts and Created goofonts.com How We Tagged Google Fonts and Created goofonts.com Apr 12, 2025 pm 12:02 PM

GooFonts is a side project signed by a developer-wife and a designer-husband, both of them big fans of typography. We’ve been tagging Google

Where should 'Subscribe to Podcast' link to? Where should 'Subscribe to Podcast' link to? Apr 16, 2025 pm 12:04 PM

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

See all articles