Last active
October 2, 2015 12:30
-
-
Save yuheiy/77c54fcc48d12e61e850 to your computer and use it in GitHub Desktop.
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
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