Drops circles with transition
Last active
March 11, 2018 19:18
-
-
Save pvernier/b7c2a8f55bf69377298dd444e304c567 to your computer and use it in GitHub Desktop.
Drop circles with transition
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
license: gpl-3.0 |
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> | |
<head> | |
<meta charset="utf-8"> | |
<style type="text/css"> | |
svg { | |
background-color: #4d4d4d; | |
width: 500px; | |
height: 500px; | |
} | |
circle { | |
fill: #b2182b; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
</body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script type="text/javascript"> | |
var svg = d3.select("svg") | |
// X coordinates of 25 circles | |
var coordsX = [10, 30, 50, 70, 90, 110, 130, 150, 170, | |
190, 210, 230, 250, 270, 290, 310, 330, | |
350, 370, 390, 410, 430, 450, 470, 490] | |
svg.selectAll("circle") | |
.data(coordsX) | |
.enter().append("circle") | |
.attr("cx", function(d) {return d}) | |
.attr("cy", 10) | |
.attr("r", 10) | |
d3.selectAll("circle") | |
.transition() | |
.delay(function(d, i) {return i*200}) | |
.duration(1000) | |
.attr("cy", "490"); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment