【发布时间】:2017-07-13 14:13:21
【问题描述】:
刚接触 React 我有这个问题 - 我有两个 react 组件,父组件是:
class Container extends Component {
render(){
if(!this.props.someProps){
return (
<div className="container-text">
<Intro />
</div>
)
} else {
return(
<div className="container-text">
Some text
</div>
)
}
}
}
父组件根据一些道具渲染子组件。子组件是:
export default class Intro extends Component{
constructor(props){
super(props)
this.state={
animated: false
}
}
componentDidMount(){
this.setState({
animated:true
})
}
render(){
return(
<CSSTransition
in={this.state.animated}
timeout={1000}
classNames='fade'>
<div>
<div className='intro-text'>
<p>choose</p>
<p>the</p>
<p>situation</p>
</div>
</div>
</CSSTransition>
)
}
}
当组件最初安装时,我确实得到了淡入淡出动画,但我不明白当它离开 DOM 时如何为它制作动画(所以基本上当 this.props.someProps 为真并且在容器类)?
【问题讨论】:
标签: javascript reactjs css-animations transition