Skip to content

Instantly share code, notes, and snippets.

@lazyTai
Created September 22, 2017 21:41
Show Gist options
  • Save lazyTai/b530b69064676b77908109090fc94757 to your computer and use it in GitHub Desktop.
Save lazyTai/b530b69064676b77908109090fc94757 to your computer and use it in GitHub Desktop.
react- motion
import React from 'react'
import {Motion, spring} from 'react-motion'
import './css/demo1.css'
export default class Demo1 extends React.Component {
constructor(props) {
super(props)
this.state = {
open: false
}
}
handMouseDown(e) {
e.preventDefault();
var me = this;
this.setState({
open: !me.state.open
})
}
render() {
return <div>
<button onMouseDown={this.handMouseDown.bind(this)}>
anniu
</button>
<Motion style={{x: spring(this.state.open ? 400 : 0)}}>
{({x}) => {
return <div className="demo1">
<div className="demo1-block" style={{
transform: `translate3d(${x}px,0,0)`,
}}></div>
</div>
}}
</Motion>
</div>
}
}
@lazyTai
Copy link
Author

lazyTai commented Sep 22, 2017

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment