Skip to content

Instantly share code, notes, and snippets.

@niorad
Created December 6, 2013 12:50
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 niorad/7823240 to your computer and use it in GitHub Desktop.
Save niorad/7823240 to your computer and use it in GitHub Desktop.
This script can be used to achieve a SVG-Animation-Effect similar to the one on http://www.polygon.com/a/ps4-review It takes all paths in an SVG-Element, hides them and draws them into the page. The method is explained in http://product.voxmedia.com/post/68085482982/polygon-feature-design-svg-animations-for-fun-and An example can be found at htt…
//inspired by http://product.voxmedia.com/post/68085482982/polygon-feature-design-svg-animations-for-fun-and
function drawSVGPaths() {
'use strict';
//grab all PATHs from an SVG-Element
var paths = $('.svganimate path');
//for each PATH..
$.each( paths, function() {
//get the total length
var totalLength = this.getTotalLength();
//set PATHs to invisible
$(this).css({
'stroke-dashoffset': totalLength,
'stroke-dasharray': totalLength + ' ' + totalLength
});
//animate
$(this).animate({
'stroke-dashoffset': 0
}, 1200);
});
}
drawSVGPaths();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment