【发布时间】:2026-01-07 05:00:02
【问题描述】:
如果单击索引 0,该方法将不起作用。如果单击索引 0,则 1 和 2 将停止工作。如果我在 1 或 2 上单击 2 次,则滑块将转到所需的幻灯片。但是零索引根本不起作用。请告诉我,可能是什么问题?
<Swiper
onMomentumScrollEnd={(e, state, context) => this.setState({index:
state.index})}
ref={(swiper) => {this.swiper = swiper;}}
showsButtons={false}
width={500}
height={500}
showsPagination={false}
index={0}
loop={true} >
<View>
<Text>One</Text>
</View>
<View>
<Text>Two</Text>
</View>
<View>
<Text>Three</Text>
</View>
</Swiper>
<Text onPress={()=>{this.swiper.scrollBy(0, true)}}>One</Text>
<Text onPress={()=>{this.swiper.scrollBy(1, true)}}>Two</Text>
<Text onPress={()=>{this.swiper.scrollBy(2, true)}}>Three</Text>
【问题讨论】:
-
scrollBy按给定索引滚动(相对于当前索引)。这就是scrollBy(0)不起作用的原因。 -
感谢您解释方法是如何安排的
标签: reactjs react-native swiper