Skip to content

Instantly share code, notes, and snippets.

@pleasetrythisathome
Created March 19, 2014 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pleasetrythisathome/9647688 to your computer and use it in GitHub Desktop.
Save pleasetrythisathome/9647688 to your computer and use it in GitHub Desktop.
state animation for React.js using d3.js and some underscore.js sugar
animate: function(attr, targetValue, duration, ease) {
var cmp = this;
var interpolator;
if (_.isFunction(targetValue)) {
interpolator = targetValue;
} else {
interpolator = d3.interpolate(this.state[attr], targetValue);
}
return d3.transition()
.duration(duration || 500)
.ease(ease || "cubic-in-out")
.tween(attr, function() {
return function(t) {
cmp.setState(_.object([attr], [interpolator(t)]));
};
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment