我更改了通過時間間隔呈現的組件。反應:如何動畫渲染組件的變化?
我希望每次發生更改時都能夠添加動畫。什麼是最好的方式去做呢?
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
)
}
編輯:
也在試圖利用 '反應 - 插件 - CSS-過渡小組' 時,我得到了以下錯誤:
在我看來,最簡單的就是使用CSS3過渡。你根據你的狀態給你的元素一個類,這會改變元素的樣式。您可以使用CSS3轉換(或CSS3動畫)轉換此樣式。 – stinodes