短视频平台搭建,淡入淡出 支持左滑右滑轮播图

短视频平台搭建,淡入淡出 支持左滑右滑轮播图

<template>
  <view class="grapSwiper">
    <view class="banner" @touchstart="touchStart" @touchend="touchEnd">
      <image v-for="(value,index) in swiperList" :key="index" class="pic" :src="value.imagePath" :animation="num==index?showpic:hidepic"/>
      <view class="snipper">
        <view class="sniItem" v-for="(item,ind) in swiperList" :key="ind" :class="num==ind?'activeItem':''"></view>
      </view>
    </view>
  </view>
</template>
<script>
 
export default {
  name: 'grapSwiper',
  data () {
    return {
      touchStartX: 0,  // 触屏起始点x  
      touchStartY: 0,  // 触屏起始点y  
      swiperList:[
        {
          imagePath:'https://pla.o-banks.cn/attach/mgrImg/20220110/1641806731686.png'
        },
        {
         imagePath:'https://pla.o-banks.cn/attach/mgrImg/20210923/1632361307137.png'
        },
        {
          imagePath:'https://pla.o-banks.cn/attach/mgrImg/20210916/1631775560384.png'
        }
      ],
      setTime:null,
      num:0,
      timeCount:5000,
      showpic:null,
      hidepic:null
    }
  },
  created () {
  },
  mounted(){
    this.initSwiper();
  },
  methods:{
    initSwiper(){
      const animation = uni.createAnimation({}) //创建一个动画实例
      this.setTime = setInterval(() => {
        this.num++
        if(this.num >this.swiperList.length-1){
          this.num = 0
        }
        //淡入
        animation.opacity(1).step({duration:300}) //描述动画
        this.showpic = animation.export()
        //淡出
        animation.opacity(0).step({duration:300})
        this.hidepic=animation.export()
 
      }, this.timeCount);
    },
    touchStart(e) {  
      this.touchStartX = e.touches[0].clientX;  
      this.touchStartY = e.touches[0].clientY;  
    },  
    touchEnd(e) {  
      let deltaX = e.changedTouches[0].clientX - this.touchStartX;  
      let deltaY = e.changedTouches[0].clientY - this.touchStartY;  
      if (Math.abs(deltaX) > 50 && Math.abs(deltaX) > Math.abs(deltaY)) {  
        // 左滑右滑时重新初始化定时器
        clearInterval(this.setTime)
        this.initSwiper();
 
        if (deltaX >= 0) {  
          this.num--
          if(this.num <0){
            this.num = this.swiperList.length-1
          }
        } else {  
          this.num++
          if(this.num >this.swiperList.length-1){
            this.num = 0
          }
        }  
      } else {  
        console.log("可能是误触!")  
      }  
    }, 
  },
  destroyed(){
    clearInterval(this.setTime)
  }
}
</script>
 
<style lang="scss" scoped>
  .grapSwiper{
    .banner{
      width: 750rpx;
      height: 640rpx;
      position: relative;
      .pic{
        width: 750rpx;
        height: 640rpx;
        position: absolute;
      }
      .snipper{
        position: absolute;
        width: 100%;
        height: 2rpx;
        top: 210rpx;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        .sniItem{
          width: 15rpx;
          height: 2rpx;
          background: #FFFFFF;
          opacity: 0.4;
          border-radius: 5rpx;
          margin-right: 6rpx;
        }
        .activeItem{
          width: 25rpx;
          background: #FFFFFF;
          opacity: 1;
        }
      }
    }
  }
</style>

以上就是短视频平台搭建,淡入淡出 支持左滑右滑轮播图, 更多内容欢迎关注之后的文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值