Skip to content

Instantly share code, notes, and snippets.

@kirjavascript
Last active January 5, 2016 16:24
Show Gist options
  • Save kirjavascript/3364c7c6dbd9436a9f52 to your computer and use it in GitHub Desktop.
Save kirjavascript/3364c7c6dbd9436a9f52 to your computer and use it in GitHub Desktop.
stroke dash hax with Snap.svg.js
<!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>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment