An example of using transition.styleTween to avoid using the computed style value, and instead use the style value as-set.
Last active
February 9, 2016 02:00
-
-
Save mbostock/6909550 to your computer and use it in GitHub Desktop.
Non-Computed Style Tween
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> | |
<meta charset="utf-8"> | |
<body style="background:brown;"> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
d3.select("body").transition() | |
.duration(750) | |
.call(styleTween, "background", "steelblue") | |
.transition() | |
.call(styleTween, "background", "black"); | |
function styleTween(transition, name, value) { | |
transition.styleTween(name, function() { | |
return d3.interpolate(this.style[name], value); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment