• Stars
    star
    4,370
  • Rank 9,425 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An easy way to animate SVG elements.

Walkway devDependency Status

I loved the animations for the polygon ps4 review a few months back and decided to create a small library to re-create them (simple demo).

It supports path, line and polyline elements.

Download

yarn

yarn add walkway.js

npm

npm install walkway.js

CDN

https://cdn.jsdelivr.net/npm/walkway.js/src/walkway.min.js

How to use

Create a new Walkway instance with a supplied options object. When you want to start animating call .draw on the returned instance providing an optional callback that will be called when drawing is complete.

// Create a new instance
var svg = new Walkway(options);
// Draw when ready, providing an optional callback
svg.draw(callback);

// Options passed in as an object, see options below.
var svg = new Walkway({ selector: '#test'});

// Overwriting defaults
var svg = new Walkway({
  selector: '#test',
  duration: '2000',
  // can pass in a function or a string like 'easeOutQuint'
  easing: function (t) {
    return t * t;
  }
});

svg.draw();

// If you don't want to change the default options you can
// also supply the constructor with a selector string.
var svg = new Walkway('#test');

svg.draw(function() {
  console.log('Animation finished');
});

All animations will automatically complete when the window containing them loses focus, to another tab, for example. You can also choose to restart all animations in an event handler. To restart every animation when the window gains focus again, you can do:

document.addEventListener('visibilitychange', function() {
  if (!document.hidden) {
    svg.redraw();
  }
}, false);

Options

  • selector (mandatory) - The selector of the parent element (usually will be a specific svg element)
  • duration - Time the animation should run for, in ms. Default is 400.
  • easing - Name of the easing function used for drawing. Default is 'easeInOutCubic'. You can also supply your own function that will be passed the progress and should return a value in the range of [0, 1];

Easing

All credit for the built-in easing functions go to gre from this gist.

Gotchas

Sometimes when exporting from a program like Illustrator elements have no stroke style attached to them. This results in confusion when Walkway starts the animation and nothing shows up. Just be sure to add base styles that can be overwritten if required.

svg {
  path, line, polyline {
    stroke: #fff
    stroke-width: 2px
  }

  path {
    fill: transparent
  }
}

Demo

View the example link provided near the top of this README or see it in action on my website.

More Repositories

1

loaders.css

Delightful, performance-focused pure css loading animations.
CSS
10,199
star
2

rb-readline

Pure-Ruby Readline Implementation
Ruby
245
star
3

typeout

Type and retype text in the browser.
JavaScript
87
star
4

OctoPanel

A simple, clean and responsive theme for Octopress.
CSS
58
star
5

TypeWriter

Simulate typing on a page.
JavaScript
48
star
6

uiscript

A web UI manipulation language for humans
JavaScript
30
star
7

Progress

Progress.js is an online tool that allows students to visualise and forecast academic grades
JavaScript
14
star
8

git-identify

Easily configure different git identities on the same machine
Shell
13
star
9

Spotlight.js

A lightweight JavaScript library to bring attention to any page element
JavaScript
9
star
10

meteor-foundation-5

An atmosphere smart package for foundation 5.
CSS
7
star
11

headway

Easy ansi style string parsing for the terminal
JavaScript
5
star
12

angular-hackathon

An opinionated node boilerplate for angular applications.
JavaScript
4
star
13

laravel-auth-skeleton

A boilerplate Laravel application that implements basic authentication.
PHP
4
star
14

js-structures

A playground for creating interesting data structures in JavaScript.
JavaScript
3
star
15

Sweet

A sweet VPN desktop client
JavaScript
3
star
16

node-todo

JavaScript
3
star
17

checks

Standalone type checks for JavaScript
JavaScript
2
star
18

learning-rust

A Rust playground.
Rust
2
star
19

ancee

ansi style color codes
JavaScript
2
star
20

owlci

A continuous integration tool for diffing visual layouts.
Ruby
2
star
21

shell-helpers

A repo full of helpful shell code snippets
Shell
2
star
22

grader

Meteor application to forecast grades
JavaScript
1
star
23

oliver

Ask for permissions in the browser.
JavaScript
1
star
24

Konami

A tiny library for responding to the konami code
JavaScript
1
star
25

tasks

A small terminal task manager
JavaScript
1
star
26

godaddy-api

Ruby
1
star
27

go-task-manager

A simple terminal task manager written in Go
Go
1
star
28

strgen

A ruby string generator
Ruby
1
star
29

geeny

A tiny, go arg parser
Go
1
star
30

fcount

Recursively count file types.
JavaScript
1
star
31

clong

Collaborative pong in a web browser
JavaScript
1
star