Skip to content

Instantly share code, notes, and snippets.

@cscuderi
Created September 1, 2014 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cscuderi/9dd0c205d0dc7eb27731 to your computer and use it in GitHub Desktop.
Save cscuderi/9dd0c205d0dc7eb27731 to your computer and use it in GitHub Desktop.
Animate SVG path
var path = document.querySelector('.squiggle-animated path');
var length = path.getTotalLength();
// Clear any previous transition
path.style.transition = path.style.WebkitTransition =
'none';
// Set up the starting positions
path.style.strokeDasharray = length + ' ' + length;
path.style.strokeDashoffset = length;
// Trigger a layout so styles are calculated & the browser
// picks up the starting position before animating
path.getBoundingClientRect();
// Define our transition
path.style.transition = path.style.WebkitTransition =
'stroke-dashoffset 2s ease-in-out';
// Go!
path.style.strokeDashoffset = '0';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment