Skip to content

Instantly share code, notes, and snippets.

@seemantk
Last active September 9, 2018 18:38
Show Gist options
  • Save seemantk/9c76316a783fe74132ab204828754cb7 to your computer and use it in GitHub Desktop.
Save seemantk/9c76316a783fe74132ab204828754cb7 to your computer and use it in GitHub Desktop.
75 Years of Batman logos
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.
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>I'm...Batman</title>
</head>
<body>
<svg width="900" height="600" viewBox="0 0 150 100">
<path id="batlogo"></path>
</svg>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
d3.xml("batman-logos.svg")
.then(mainfn)
;
d3.select("body")
.style("background-color", "yellow")
;
function mainfn(xml) {
var paths = Array.from(xml.getElementsByTagName('path'))
.map(d => d.getAttribute('d'))
.reverse()
;
d3.select("path#batlogo")
.call(animate)
;
function animate(sel) {
var start = paths.shift()
, end = paths[0];
paths.push(start);
sel.datum({start, end})
.transition()
.duration(1500)
.ease(d3.easeQuad)
.attrTween("d", function(d) {
return d3.interpolate(d.start, d.end);
})
.on("end", function() { sel.call(animate); });
} // animate()
} // mainfn()
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment