Skip to content

Instantly share code, notes, and snippets.

@mbostock mbostock/.block
Last active Feb 9, 2016

Embed
What would you like to do?
Non-Computed Style Tween
license: gpl-3.0

An example of using transition.styleTween to avoid using the computed style value, and instead use the style value as-set.

<!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
You can’t perform that action at this time.