小程序swiper判断是向左还是向右滑动
// 这个用uniapp 写的,vue语法。自己可以改成小程序代码就行。自己定义一个preIndex变量记录上个索引。
<swiper @change="animationChange" style="height:800rpx;" circular
autoplay="true" interval="3000" duration="1000">
<swiper-item v-for="(item,index) in swiperList">
<image style="height:800rpx;width:100%;" :src="item.imageUrl"></image>
</swiper-item>
</swiper>
animationChange(val,aa) {
// console.log("默认索引",val.detail.current)
if(this.preIndex == this.swiperList.length -1 && val.detail.current == 0 && this.preIndex > val.detail.current){
// 图片向左
console.log('图片向左');
}else if(val.detail.current == this.swiperList.length -1 && this.preIndex == 0 && this.preIndex < val.detail.current){
// 图片向右
console.log('图片向右');
}else if(this.preIndex > val.detail.current){
// 图片向右
console.log('图片向右');
}else if(this.preIndex < val.detail.current){
// 图片向左
console.log('图片向左');
}
// 记录当前
this.preIndex = current;
},