Last active
January 5, 2016 16:24
-
-
Save kirjavascript/3364c7c6dbd9436a9f52 to your computer and use it in GitHub Desktop.
stroke dash hax with Snap.svg.js
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>stroke dash hax with Snap.svg.js</title> | |
</head> | |
<body> | |
<svg></svg> | |
</body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.4.1/snap.svg-min.js"></script> | |
<script> | |
var yep = Snap('svg'); | |
Snap.load('yep.svg', d => { | |
yep | |
.attr({ | |
viewBox:"-5, -5, 205, 120" | |
}) | |
d.selectAll('*').forEach(p => yep.append(p)) | |
// emulates line drawing by using some stroke-dash hax | |
~function dasher(obj,i) { | |
var path = obj[i]; | |
var len = path.getTotalLength(); | |
return path.attr({ | |
strokeWidth:3, | |
strokeDasharray:len, | |
strokeDashoffset:len | |
}) | |
.animate({strokeDashoffset:0},len,mina.linear,e => { | |
++i<obj.length && dasher(obj,i) | |
}) | |
} (yep.selectAll("path"),0) | |
}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment