`
renderRadar = () => {
clearInterval(radarTimer);
if (this.state.isPlayRadar) {
radarTimer = setInterval(() => {
this.setState({
radarImg: images[this.currentIndex],
craImg: this.currentIndex === 0 ? convection['iso'][0].imgUrl : convection['iso'][Math.ceil(this.currentIndex/10)-1].imgUrl
})
if (this.currentIndex < images.length-1) {
this.currentIndex += 1;
} else {
this.currentIndex = 0;
}
}, 200)
}
}
`
render
`
<div style={{padding: '20px'}}>
<img style={{width: '50%',margin: 0}} src={radarImg} alt='radar' onError={e => e.target.src = ErrorImg}/>
<img style={{width: '50%',margin: 0}} src={craImg} alt='再分析' onError={e => e.target.src = ErrorImg}/>
</div>
`
当图片都加载完成之后再调用定时器不让其重新加载,让其根据缓存的图片进行定时切换
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…