以下是从github的demo0-simple-transition的代码。 Link 如何向移动div元素添加内容。 希望使用这种变化来运行一个飞出菜单,但似乎无法弄清楚如何获取内容。 感谢React-motion div嵌套
import React from 'react';
import {Motion, spring} from '../../src/react-motion';
const Demo = React.createClass({
getInitialState() {
return {open: false};
},
handleMouseDown() {
this.setState({open: !this.state.open});
},
handleTouchStart(e) {
e.preventDefault();
this.handleMouseDown();
},
render() {
return (
<div>
<button
onMouseDown={this.handleMouseDown}
onTouchStart={this.handleTouchStart}>
Toggle
</button>
<Motion style={{x: spring(this.state.open ? 400 : 0)}}>
{({x}) =>
// children is a callback which should accept the current value of
// `style`
<div className="demo0">
<div className="demo0-block" style={{
WebkitTransform: `translate3d(${x}px, 0, 0)`,
transform: `translate3d(${x}px, 0, 0)`,
}} />
</div>
}
</Motion>
</div>
);
},
});
export default Demo;
谢谢汤姆,但是这并没有让我进入demo0-block。这只是另一个顶部。我正在跳跃嵌套其他元素,以便他们继承这个动作。 – JGC