我有这个功能,它在点击时注册了。
mobileZoomClick () {
const elem = this.state.scale.carousel
if (this.state.zoom && elem.scale < 1.1) {
this.zoomOut()
}
}
<div ref='carousel'
onClick={this.mobileZoomClick.bind(this)}
className='carousel' style={this.fullscreen('carousel')}
test={this.state.carouselTransition === 'transitionEnd' && !this.state.zoom && this.flickity()}
>
我想将this.flickity()添加到函数中:
mobileZoomClick () {
const elem = this.state.scale.carousel
if (this.state.zoom && elem.scale < 1.1) {
this.zoomOut()
}
if(this.state.carouselTransition === 'transitionEnd' && !this.state.zoom){
this.flickity()
}
}
但我需要更新状态变化。当前的解决方案在技术上有效,但会抛出错误。
这是新状态的设置方式(第一个用于检查某些元素是否在css转换中:
transitionState (target) {
// den här behöver fallback för inte transition
const done = (e) => {
this.setState({[stateName]: 'transitionEnd'}, () => {
this.setState({[stateName]: 'transitionComplete'})
})
e.target.removeEventListener(e.type, done)
}
const elem = this.refs[target]
const stateName = target + 'Transition'
this.setState({[stateName]: 'transitionStarted'})
elem.addEventListener('transitionend', done)
}
这是用于缩小: zoomOut(){this.setState({zoom:false})}