Skip to content

Instantly share code, notes, and snippets.

@AlainRo
Last active February 28, 2018 14:48
Show Gist options
  • Save AlainRo/7db7497b82991d59f99cebc8d643639d to your computer and use it in GitHub Desktop.
Save AlainRo/7db7497b82991d59f99cebc8d643639d to your computer and use it in GitHub Desktop.
d3js Exercice 5 - transitions
license: mit

Transitions

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
circle {
fill: steelblue;
}
</style>
</head>
<body>
<svg width="600" height="400">
<circle cx="20" cy="20" r="20" />
<circle cx="20" cy="70" r="20" />
<circle cx="20" cy="120" r="20" />
</svg>
<div>
<button onclick="go()">Go</button>
<button onclick="go(true)">Go Back</button>
</div>
<script>
function go (reverse) {
d3.selectAll('circle')
.transition()
.delay((d, i) => i * 250)
.duration(1000)
.ease(d3.easeLinear)
.attr('cx', reverse ? 20 : 500)
}
// Exercice: essayer de changer easeLinear par les autres possibilités offertes par d3 easeCubicOut, easeBounceOut, ...
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment