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