Last active
January 7, 2016 17:40
-
-
Save kirjavascript/d2715bf7d2a1635f5512 to your computer and use it in GitHub Desktop.
clip path 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:"0,0,1040,600" | |
}) | |
yep.append(d.select("defs")); | |
d.selectAll('.path').forEach(p => yep.append(p)) | |
dasher(yep.select("#y"),50,() => { | |
dasher(yep.select("#e"),45,() => { | |
dasher(yep.select("#p"),45,() => { | |
dasher(yep.select("#ex1"),60,() => { | |
dasher(yep.select("#ex2"),55,() => { | |
// when you see nesting like this you know it's time to refactor | |
}); | |
}); | |
}); | |
}); | |
}); | |
// emulates line drawing by using some stroke-dash hax | |
function dasher(obj,w,callback) { | |
var path = obj; | |
var len = path.getTotalLength(); | |
return path.attr({ | |
strokeWidth:w, | |
strokeDasharray:len, | |
strokeDashoffset:len | |
}) | |
.animate({strokeDashoffset:0},len/3,mina.linear,callback) | |
} | |
}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment