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

Overview

Lazy Line Painter

undefined undefined undefined undefined

Lazy Line Painter

lazylinepainter.info

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
npm i lazy-line-painter
CDN
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/lazy-line-painter-1.9.4.min.js"></script>
DOWNLOAD
<script src="./libs/lazylinepainter-1.9.4.js"></script>



Quick Start

The most basic, no-frills implementation;

// import LazyLinePainter
import LazyLinePainter from 'lazy-line-painter'

// select your svg
let el = document.querySelector('#my-svg')

// initialise & configure LazyLinePainter
let 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.

let 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
}

let svg = document.querySelector('#my-svg') 
let 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 attribues
	data-llp-stroke-width
	data-llp-stroke-color
	data-llp-stroke-opacity
	data-llp-stroke-cap
	data-llp-stroke-join 
	data-llp-stroke-dash

	// animation attribues
	data-llp-duration (ms)
	data-llp-delay (ms) // delay offset from start of timeline
	data-llp-reverse (default = false)
	data-llp-ease (default = 'easeLinear')
/>



API Reference

Methods

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

myAnimation.paint( { 
	reverse : true, 
	ease : 'easeExpoOut' 
});

Erase - paint can still be called on the element after it has been erased;

myAnimation.erase();

Pause

myAnimation.pause();

Resume

myAnimation.resume();

Set - set options after initialisation

// progress - sets path position, second param accepts a number between 0 - 1
myAnimation.set('progress', value);

Get - returns all lazylinepainter data;

myAnimation.get();

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

Cam O'Connell @ http://merriment.info/
Email - [email protected]

Comments
  • Dots before draw on Safari and Firefox

    Dots before draw on Safari and Firefox

    Hi,

    I have a problem and can't solve it yet. Dots appears before the animation...Does anyone knows how to solve this? You can see it here: http://www.fevre-gaucher.com/dev/

    On Chrome there is no problem, it's only on Firefox and Safari (may be on IE too but I can't check it)

    Thanks very much and thanks for your work on this code

    opened by ghost 20
  • Scale your svg

    Scale your svg

    I was wondering how to scale your svg. Thats pretty easy

    add a ratioScale option parameters, with default : 1

    and put that parameter with setviewbox function in init :

    init: function(c) {
            return this.each(function() {
                var a = e(this),
                    b = a.data("lazyLinePainter");
                a.addClass("lazy-line");
                if (!b) {
                    var b = e.extend({
                        width: null,
                        height: null,
                        strokeWidth: 2,
                        strokeColor: "#000",
                        strokeCap: "round",
                        strokeJoin: "round",
                        ratioScale : null,
                        strokeOpacity: 1,
                        strokeDash: null,
                        onComplete: null,
                        delay: null,
                        overrideKey: null
                    }, c),
                        h = null === b.overrideKey ? a.attr("id").replace("#", "") : b.overrideKey,
                        f = b.svgData[h].dimensions.width,
                        k = b.svgData[h].dimensions.height;
                    b.svgData = b.svgData[h].strokepath;
                    null ===
                        b.width && (b.width = f);
                    null === b.height && (b.height = k);
                    h = a.attr("id");
                    f = new Raphael(h, f*b.ratioScale, k*b.ratioScale);
                    f.setViewBox(0,0,b.width / b.ratioScale,b.height / b.ratioScale,true);
                    a.data("lazyLinePainter", {
                        svgData: b.svgData,
                        width: b.width,
                        height: b.height,
                        strokeWidth: b.strokeWidth,
                        strokeColor: b.strokeColor,
                        strokeCap: b.strokeCap,
                        strokeJoin: b.strokeJoin,
                        strokeOpacity: b.strokeOpacity,
                        strokeDash: b.strokeDash,
                        onComplete: b.onComplete,
                        delay: b.delay,
                        overrideKey: b.overrideKey,
                        paper: f,
                        count: 1,
                        complete: !1,
                        playhead: 0,
                        setTimeOutHandler: []
                    })
                }
            })
    

    Then in your constructor :

     $(document).ready(function(){ 
       // Setup your Lazy Line element.
        // see README file for more settings
        $('#svg').lazylinepainter({
            'svgData': svgData,
            'strokeWidth': 1,
            'strokeColor': '#ffffff',
            'ratioScale' : 2,
            'onComplete': function() {
    
            }
        })
    
        // Paint your Lazy Line, that easy!
        $('#svg').lazylinepainter('paint');
     });
    

    your svg is 2x time larger.

    It works with the very very last version of Raphael. ( viewbox problem with under version of raphael ! )

    Keep going !

    opened by Samsy 10
  • adding color inside svg

    adding color inside svg

    Is there a way were I can add color inside the SVG. I was looking at the documentation hoping to finding something like "fill" to put color inside the SVG. Basically the concept is once the svg finishes animating it will add color inside.

    opened by clestcruz 8
  • Responsive width and height

    Responsive width and height

    Is there anyway of creating a svg with a percentage so when you reduce the screens width & height it fits? I assume there's no way of doing this as it's already a coded svg

    opened by Lippiun 8
  • Speed of lazy line painter

    Speed of lazy line painter

    Hello,

    Hope you are in the best of health, wanted to inquire that how can we manage the draw speed of the animation ? thanks in advance.

    Regards, Kamil

    opened by kamil-incubasys 6
  • Erase method defect

    Erase method defect

    'Init' method, count is set to 1: 'count' : 1, 'Erase' method, count is set to 0: d.count = 0;

    • but should be 1. Consequent calls (with callbacks) of 'Paint -> Erase -> Paint' didn't work for me, changed count to 1 in 'Erase' method and it worked.
    opened by maxim-saplin 6
  • Smoother animation

    Smoother animation

    Hi! Just want to share an idea. It is possible to use css-transition n stroke-dasharray to create nice painting animations.

    Benefits:

    • super performance (even on mobile)
    • smooth animation

    Here is my small example -- http://codepen.io/H1D/pen/KhgFw

    opened by H1D 6
  • (anonymous function) issue

    (anonymous function) issue

    I don't get this issue when using older versions of lazy line painter (1.1) but I am thrown plenty of errors when attempting to use 1.7. Anonymous function is being thrown out in my own code:

     $(document).ready(function(){ 
           $('#line').lazylinepainter( // Issue on this line
      {
        "svgData": pathObj,
        "strokeWidth": 2,
        "strokeColor": "#000",
        'drawsequential': false,
        }).lazylinepainter('paint'); 
     });
    

    Aswell as a whole bunch of errors in the actual path code and the lazy line painter 1.7 js code:

    Error: Invalid value for <path> attribute d="M29.6,315. L 24.9,315.9 21.9,314.9 14.6,314.9 9,313.4 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M36.9,313. L 35.6,310.8 36.9,235.2 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M33.2,326. L 136.4,339 146.3,338.1 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M193.5,336. L 193.5,308.2 199.2,308.2 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M323.6,318. L 332.1,356.2 350.9,350.9 341.7,315.3 z"m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M-3,333. L 599.4,406.1 670.9,410.4 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M412.1,358. L 412.1,374.3 390.1,357.1 390.1,369.4 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M493.6,192. L 412.1,199 425.3,187.1 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M417.6,189. L 404.6,197 344,195.3 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M266.9,202. L 248.6,211.1 125.7,223.7 146.7,211.6 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.js:7975 Error: Invalid value for <path> attribute d="M261.8,166. L 261.8,152.4 245.9,154.5 245.8,158.9 250.1,158.7 250.1,163.8   241.8,164.7 241.8,155.7 241.1,155.8 "m.extend.attr @ jquery.js:7975m.access @ jquery.js:4171m.access @ jquery.js:4143m.fn.extend.attr @ jquery.js:7933_getPath @ jquery.lazylinepainter-1.7.0.js:580_setupPaths @ jquery.lazylinepainter-1.7.0.js:330(anonymous function) @ jquery.lazylinepainter-1.7.0.js:80m.extend.each @ jquery.js:384m.fn.m.each @ jquery.js:136methods.init @ jquery.lazylinepainter-1.7.0.js:66$.fn.lazylinepainter @ jquery.lazylinepainter-1.7.0.js:701(anonymous function) @ ?page_id=15:1025j @ jquery.js:3148k.fireWith @ jquery.js:3260m.extend.ready @ jquery.js:3472J @ jquery.js:3503
    jquery.lazylinepainter-1.7.0.js:540 Uncaught TypeError: Cannot read property 'x' of undefined
    

    The animation doesn't paint at all, but a blank space is reserved in the dom

    opened by davidhigginson 4
  • Would you please update npm?

    Would you please update npm?

    Hi,

    I want to get latest lazy-line-painter(1.8.0) using npm.

    'Removed : jQuery as dependency' , very good!

    https://www.npmjs.com/package/lazy-line-painter

    Would you please update npm?

    opened by okutani-t 3
  • Dot's Before Drawing on IE

    Dot's Before Drawing on IE

    Hi this is an issue that seems to effect version 1.5 - 1.7 on Internet Explorer 11 and 10.

    Before the lines are drawn on the start points appear as little circles like so:-

    lazy-problem

    I'm happy to provide more information if it helps.

    opened by EukleiaCraig 3
  • No stroke-dasharray available via CSS

    No stroke-dasharray available via CSS

    Hello people.

    First of all excuse my English. Hope you can understand the point.

    From the code in the jquery.lazylinepainter.js file I can gather (from my lack of better knowledge of JavaScript and jQuery) that the dasharray allows the script to animate the line. How can I alter this property so I can have, lets say, a dashed line or a dotted one?

    Thanks.

    --Update--

    I tried adding the property in the var of the pathObj (Were all the info from the SVG goes) but it doesnt work, also tried in CSS with div > svg > path { stroke-dasharray: 5,5 } and it makes it dashed but not animated.

    opened by jorgeepena 3
  • lazy_line_painter__WEBPACK_IMPORTED_MODULE_1__.LazyLinePainter is not a constructor

    lazy_line_painter__WEBPACK_IMPORTED_MODULE_1__.LazyLinePainter is not a constructor

    I am working with lazy-line-painter in Angular js

    I have installed via npm i lazy-line-painter. when i import in a component it shows this error

    ERROR TypeError: lazy_line_painter__WEBPACK_IMPORTED_MODULE_1__.LazyLinePainter is not a constructor

    opened by asadk6103 0
  • ReferenceError: window is not defined

    ReferenceError: window is not defined

    Hi,

    Your library is a cool thing, but :-) ... WIX has just added lazy-lane-painter npm to their repository according my request. Now I am trying just to import it and at this point (import lazyLinePainter from 'lazy-line-painter';) I get "ReferenceError: window is not defined"

    What's wrong?

    Just as an idea - as far as I understand you have no access to CSS using JS in WIX, maybe that's why?

    opened by akournitsky 1
  • Safari - getPointAtLength error

    Safari - getPointAtLength error

    Hi,

    I am getting a very specific error on Safari, only in version 13.1 (High Sierra).

    InvalidStateError - The object is in invalid state (getPointAtLength).

    This method is tagged as Deprecated - https://developer.mozilla.org/en-US/docs/Web/API/SVGPathElement/getPointAtLength

    Any idea, how to get around it? Thanks!

    opened by tolchai 0
  • Download Button Getting Cut Off

    Download Button Getting Cut Off

    When I upload certain svgs (ex: the words "Welcome to DouxDolci"), the Download button gets cut off on the website. There's no way to scroll to it either. I'm using an "Object to Path" function in Inkscape to make the svg.

    opened by matthewincardona 0
  • Safari - Path showing first point before animation starts

    Safari - Path showing first point before animation starts

    I have been using a previous version of LLP and I'm upgrading to the latest one. The only issue I faced so far is that in Safari, the first dot of a line is shown before the corresponding animation starts. I'm using a large strokeWidth so it makes it very noticeable.

    This is the animation when it is starting: Screen Shot 2020-01-21 at 10 17 25 the dot at the right should not be visible yet

    This is the animation halfway: Screen Shot 2020-01-21 at 10 25 37

    And this is the completed animation: Screen Shot 2020-01-21 at 10 17 29

    This is the relevant code:

    `