【无标题】

@面板轮播图

vue自适应手撸面板轮播图

轮播图布局如下,话不多说,直接上代码。
在这里插入图片描述

html

<div class="swiper-div">
      <div :ref="`imgs${index}`" :class="active?'imgs':'active'+index" v-for="(item,index) in list" :key="index">
        <img :src="item.img" alt />
      </div>
    </div>

css

.swiper-div {
  width: 100%;
  height: 23.44rem;
  position: relative;
  > div {
    width: 33.33%;
    height: 33.33%;
    position: absolute;
    padding: 0.25rem;
    > img {
      border: 1px solid black;
      width: 100%;
      height: 100%;
    }
  }
  .imgs {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .active0 {
    width: 66.66%;
    height: 66.66%;
    position: absolute;
    padding: 0.25rem;
    top: 0;
    left: 0;
    transition: all 0.5s linear;
  }
  .active1 {
    width: 33.33%;
    height: 33.33%;
    position: absolute;
    padding: 0.25rem;
    right: 0;
    top: 0;
    transition: all 0.5s linear;
  }
  .active2 {
    width: 33.33%;
    height: 33.33%;
    position: absolute;
    padding: 0.25rem;
    right: 0;
    top: 33.33%;
    transition: all 0.5s linear;
  }
  .active3 {
    width: 33.33%;
    height: 33.33%;
    position: absolute;
    padding: 0.25rem;
    right: 0;
    top: 66.66%;
    transition: all 0.5s linear;
  }
  .active4 {
    width: 33.33%;
    height: 33.33%;
    position: absolute;
    padding: 0.25rem;
    right: 33.33%;
    top: 66.66%;
    transition: all 0.5s linear;
  }
  .active5 {
    width: 33.33%;
    height: 33.33%;
    position: absolute;
    padding: 0.25rem;
    left: 0;
    top: 66.66%;
    transition: all 0.5s linear;
  }
}

js

  data() {
    return {
      active: true,
      list: [
        { img: '1' },
        { img: '2' },
        { img: '3' },
        { img: '4' },
        { img: '5' },
        { img: '6' }
      ],//需要自己添加图片路径
    }
  },
  methods: {
    startSwiper() {
      this.active = false
      this.move()
    },
    move() {
      var i = 0
      var that = this
      function fn() {
        i++
        if (i > that.list.length - 1) {
          i = 0
        }
        // console.log(i)
        switch (i) {
          case 1:
            that.oneStep()
            break
          case 2:
            that.twoStep()
            break
          case 3:
            that.threeStep()
            break
          case 4:
            that.fourStep()
            break
          case 5:
            that.fiveStep()
            break
          case 0:
            that.sixStep()
            break
        }
      }
      setInterval(fn, 3000)
    },
    oneStep() {
      this.$refs.imgs0[0].className = 'active1'
      this.$refs.imgs1[0].className = 'active2'
      this.$refs.imgs2[0].className = 'active3'
      this.$refs.imgs3[0].className = 'active4'
      this.$refs.imgs4[0].className = 'active5'
      this.$refs.imgs5[0].className = 'active0'
    },
    twoStep() {
      this.$refs.imgs0[0].className = 'active2'
      this.$refs.imgs1[0].className = 'active3'
      this.$refs.imgs2[0].className = 'active4'
      this.$refs.imgs3[0].className = 'active5'
      this.$refs.imgs4[0].className = 'active0'
      this.$refs.imgs5[0].className = 'active1'
    },
    threeStep() {
      this.$refs.imgs0[0].className = 'active3'
      this.$refs.imgs1[0].className = 'active4'
      this.$refs.imgs2[0].className = 'active5'
      this.$refs.imgs3[0].className = 'active0'
      this.$refs.imgs4[0].className = 'active1'
      this.$refs.imgs5[0].className = 'active2'
    },
    fourStep() {
      this.$refs.imgs0[0].className = 'active4'
      this.$refs.imgs1[0].className = 'active5'
      this.$refs.imgs2[0].className = 'active0'
      this.$refs.imgs3[0].className = 'active1'
      this.$refs.imgs4[0].className = 'active2'
      this.$refs.imgs5[0].className = 'active3'
    },
    fiveStep() {
      this.$refs.imgs0[0].className = 'active5'
      this.$refs.imgs1[0].className = 'active0'
      this.$refs.imgs2[0].className = 'active1'
      this.$refs.imgs3[0].className = 'active2'
      this.$refs.imgs4[0].className = 'active3'
      this.$refs.imgs5[0].className = 'active4'
    },
    sixStep() {
      this.$refs.imgs0[0].className = 'active0'
      this.$refs.imgs1[0].className = 'active1'
      this.$refs.imgs2[0].className = 'active2'
      this.$refs.imgs3[0].className = 'active3'
      this.$refs.imgs4[0].className = 'active4'
      this.$refs.imgs5[0].className = 'active5'
    }
  },
  mounted() {
    this.startSwiper()
  },
  watch: {
    active(newV) {
      this.active = newV
    }
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值