Skip to content

Instantly share code, notes, and snippets.

@yuheiy
Last active October 2, 2015 12:30
Show Gist options
  • Save yuheiy/77c54fcc48d12e61e850 to your computer and use it in GitHub Desktop.
Save yuheiy/77c54fcc48d12e61e850 to your computer and use it in GitHub Desktop.
import React from 'react';
import dynamics from 'dynamics.js';
class Box extends React.Component {
constructor(props) {
super(props);
this.state = {
x: 0,
y: 0
};
}
componentDidMount() {
dynamics.animate(this.state, {
x: 200,
y: 20
}, {
change: (e) => this.setState({x: e.x, y: e.y})
});
}
render() {
const style = {
transform: `translate(${this.state.x}px, ${this.state.y}px)`
};
return (
<div className="box" style={style}></div>
);
}
}
React.render(<Box />, document.getElementById('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment