Skip to content

Instantly share code, notes, and snippets.

Last active February 9, 2016 01:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Mirrored Easing
license: gpl-3.0

This example demonstrates mirroring an easing function such that the transition returns to its starting point upon completion. The mirror function takes an easing function as input (or the name of an easing function, such as “cubic”) and returns a mirrored easing function; the mirrored function reaches the transition destination at t = 0.5, and then returns to the transition origin at t = 1.0.

<!DOCTYPE html>
<meta charset="utf-8">
h1 {
background: white;
display: block;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 500px;
margin: auto;
text-align: center;
<h1>CLICK HERE</h1>
<script src="//"></script>
<script>"h1").on("click", function() {
.style("background", "white")
.style("background", "red");
function mirror(f) {
if (typeof f !== "function") f = d3.ease.apply(d3, arguments);
return function(t) {
return t < .5 ? f(2 * t) : f(2 - 2 * t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment