【发布时间】:2017-05-19 06:32:10
【问题描述】:
我更改了通过时间间隔呈现的组件。
我希望能够在每次发生更改时添加动画。最好的方法是什么?
constructor (props) {
super(props)
this.state = { currentComponent: 1,
numberOfComponents: 2}
}
componentWillMount() {
setInterval(() => {
if(this.state.currentComponent === 2) {
this.setState({currentComponent: 1})
} else {
this.setState({currentComponent: this.state.currentComponent + 1})
}
}, 5000)
}
render(){
let currentComponent = null;
if(this.state.currentComponent === 1) {
currentComponent = <ComponentOne/>;
} else {
currentComponent = <ComponentTwo/>;
}
return(
currentComponent
)
}
编辑:
当尝试使用“react-addons-css-transition-group”时 我收到以下错误:
【问题讨论】:
-
我认为最简单的方法是使用 CSS3 过渡。你根据你的状态给你的元素一个类,这会改变你元素的样式。您可以使用 CSS3 转换(或 CSS3 动画)转换此样式。
标签: javascript css reactjs animation