收藏
回答

swiper可以判断划动方向吗?

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 需求 swiper 客户端 6.6.7 2.2.0

swiper能不能加上,判断划动方向的功能

回答关注问题邀请回答
收藏

4 个回答

  • 禾店科技
    禾店科技
    2021-04-28

    楼主解决了吗?我也遇到了这种问题

    2021-04-28
    有用 1
    回复 1
    • 
      2023-07-24
      2023-07-24
      回复
  • 
    2023-07-24
    <template>
    <view class="seePhoto">
      <swiper
          :current="renderCurrent"
          @change="swiperChange"
          >
          <swiper-item style="width:100%;height: 100%;" v-for="(val,key) in  renderPhoto" :key="key">
          </swiper-item>
      </swiper>
    </view>
    </template>
    <script>
    export default{
      data(){
          return{
            renderPhoto:[],//要渲染的图片 只沉染二张图进行来回切换
            renderCurrent: 1,//轮播时的索引
            lastCurrent:1,//记录上一次的索上,用于判断是左滑动还是右滑动
          }
      },
      methods:{
          // 滑动时
          swiperChange(e){
            let that = this;
            this.renderCurrent = e.detail.current;
            if(this.photoArr.length > 3){
              // 右滑动  0  1  2  0  1  2
              // 左滑动  2  1  0  2  1  0
              if(e.detail.current != (this.renderPhoto.length -1) && e.detail.current > this.lastCurrent){
                  console.log("左滑动了")
              }
              else if(e.detail.current == (this.renderPhoto.length -1)  && e.detail.current > this.lastCurrent && this.lastCurrent != 0){
                console.log("左滑动了")
            } else if(e.detail.current == 0 && this.lastCurrent == (this.renderPhoto.length -1)){
              console.log("左滑动了")
            }
            else if(e.detail.current != 0 && e.detail.current < this.lastCurrent){
              console.log("右滑动了")
      } else if(e.detail.current == 0 && e.detail.current < this.lastCurrent){
          console.log("右滑动了")
      } else if(e.detail.current == (this.renderPhoto.length -1)  && e.detail.current > this.lastCurrent && this.lastCurrent == 0){
          console.log("右滑动了")
      }
      this.lastCurrent = e.detail.current;
    }
      
    },
      
      }
    
      }
    
    </script>
    
    
    
    
    2023-07-24
    有用
    回复
  • 飘逸丶麦子
    飘逸丶麦子
    2018-11-28

    自己判读吧,touch事件

    2018-11-28
    有用
    回复
  • 钱票票
    钱票票
    2018-11-27

    嗯,我也遇到这个需求

    2018-11-27
    有用
    回复 1
    • 长安
      长安
      2018-11-30

      bindtouchstart和bindtouchend通过坐标判断,也可以根据swiper的当前的current和上次的current判断

      2018-11-30
      回复
登录 后发表内容