Created
September 22, 2017 21:41
-
-
Save lazyTai/b530b69064676b77908109090fc94757 to your computer and use it in GitHub Desktop.
react-
motion
This file contains hidden or 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 {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> | |
} | |
} |
Author
lazyTai
commented
Sep 22, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment