手写简易轮播图

直接贴代码自己看效果

<template>
  <div style="width: 100%; height: 600px">
    <div class="score-contain">
      <i class="el-icon-arrow-left aa" @click="lunboAnother(isRadius - 1, true)"></i>
      <i class="el-icon-arrow-right bb" @click="lunboAnother(isRadius + 1, false)"></i>
      <img src="@/assets/a1.png" alt="" id="img" />
      <img src="@/assets/a2.png" alt="" style="width: 610px; height: 364px" id="img" />
      <img src="@/assets/a1.png" alt="" style="width: 610px; height: 364px" id="img" />
      <img src="@/assets/a4.png" alt="" style="width: 610px; height: 364px" id="img" />
      <div class="radius-contain">
        <div v-for="(item, i) in 4" :key="i" class="radius" :class="{ isCurrent: i === isRadius }"
          @click="lunboAnother(i)"></div>
      </div>
    </div>
    <el-button @click="lunboAnother(0)">开始轮播</el-button>
    <el-button @click="stop">停止轮播</el-button>
    <!-- <linePie></linePie>
   <CysPie></CysPie> -->
  </div>
</template>
<script>
// import linePie from './LinePie.vue';
// import CysPie from './CysPie.vue'
export default {
  // components: {linePie ,
  //   CysPie
  // },
  data() {
    return {
      data1: [300, 450, 90, 300, 520, 450, 150, 300], //数值
      isRadius: 0, //小圆点
      timer: null, //定时器
    };
  },
  mounted() { },
  computed: {},
  watch: {},
  methods: {
    stop() {
      this.clearInterval();
    },
    clearInterval() {
      clearInterval(this.timer);
    },
    lunboAnother(i, b) {
      let img = document.getElementById("img");
      this.clearInterval();
      if (b) {
        if (i === -1) {
          i = 3;
        }
      } else {
        if (i === 4) {
          i = 0;
        }
      }
      img.style.marginLeft = -i * 610 + "px";
      this.isRadius = i;
      this.timer = setInterval(() => {
        i += 1;
        if (i === 4) {
          i = 0;
        }
        this.isRadius = i;
        img.style.marginLeft = -i * 610 + "px";
      }, 2000);
    },
  },
};
</script>

<style lang="scss">
.score-contain {
  width: 610px;
  height: 364px;
  display: flex;
  overflow: hidden;
  margin-left: 100px;
  margin-top: 100px;
  position: relative;
  .aa {
    position: absolute;
    font-size: 40px;
    color: #fff;
    left: 20px;
    transform: translateY(-50%);
    top: 50%;
  }

  .bb {
    position: absolute;
    font-size: 40px;
    color: #fff;
    right: 20px;
    transform: translateY(-50%);
    top: 50%;
  }

  .radius-contain {
    position: absolute;
    bottom: 40px;
    left: 40px;
    display: flex;

    .radius {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color: #ecf8ff;
      margin-right: 4px;
    }

    .isCurrent {
      background-color: #87d353;
    }
  }
}
</style>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值