Skip to content

Instantly share code, notes, and snippets.

@AntonLitvin
Created April 25, 2017 11:53
Show Gist options
  • Save AntonLitvin/8c7efc69064e299bca99b637ef51441f to your computer and use it in GitHub Desktop.
Save AntonLitvin/8c7efc69064e299bca99b637ef51441f to your computer and use it in GitHub Desktop.
SVG Animate
var path = document.querySelector('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 30s ease';
// Go!
path.style.strokeDashoffset = '0';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment