Created
March 19, 2014 18:06
-
-
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
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
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