Created
December 6, 2013 12:50
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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