1
我希望用CSS過渡動畫的對象:如何在相同的功能中設置兩次樣式並作出反應?
<div style={this.setStyle()}>
setStyle() {
const style = {}
if (this.state.fullScreen) {
style.background = 'white'
style.position = 'absolute'
style.transition = 'top 2s'
style.top = '20px'
}
//here I wish to set style.top = 0
return style
}
我想首先設置style.top = 20px
(這是該項目是已經,然後重新呈現DOM,然後設置style.top = 0
觸發?動畫如何才能做到這一點
state declaration:
constructor (props) {
super(props)
this.state = {
active: -1,
fullScreen: false,
fullScreenStyle: {
background: 'transparent',
position: 'static',
top: 'auto'
}
}
this.flky = {}
}
setStyle() {
if (this.state.fullScreen) {
this.setState({
fullScreenStyle.background: 'white,
fullScreenStyle.position: 'absolute'
fullScreenStyle.top: '20px'
})
}
怎麼來的風格移到this.state.style? – Himmators
setState將狀態設置爲當前值並在此之後調用render函數 – Codesingh
是否適合您? – Codesingh