【发布时间】:2021-10-16 15:50:10
【问题描述】:
//sample piece of codes
constructor() {
super()
this.state.opacity= '0'
this.state.mover = 'translateY(-40%)'
}
this.setState({opacity:'1'})
this.setState({mover: 'translateY(-900%)'}, () => {this.setState({opacity:'0'})})
当我点击一个按钮时,我希望一个 div 出现(使用不透明度 1)并过渡到顶部并在到达顶部后淡出(使用不透明度 0)。
但它并没有像我预期的那样工作。目前,它会立即淡出。它不会等待过渡结束。我希望它在过渡结束后淡出。
React 有没有办法修复它?我对反应很陌生。非常感谢您的帮助。谢谢。
【问题讨论】:
-
我认为解决这个问题的唯一方法是使用“react-transition-group”。我必须做一个 POC 来确认。 reactcommunity.org/react-transition-group
标签: css reactjs css-transitions css-transforms react-class-based-component