PC端vue动画制作轮播图

<template>
  <div class="wrapper">
    <div>21221</div>
    <div v-on:mouseover="stop()" v-on:mouseout="move()" class="swiper">
      <transition-group tag="ul" name="image">
        <li v-for="(items, index) in list" v-show="index === num" :key="items">
          <img :src="items" alt="" />
        </li>
      </transition-group>
      <div class="circle">
        <span
          v-for="(items, index) in data"
          class="nav"
          @click="change(index)"
          :class="{ active: index == num }"
        ></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
    
    
  data() {
    
    
    return {
    
    
      data: ["1", "2", "3"],
      time: "",
      num: 0,
      list: [
        "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534136662314&di=af7ec227db5e118a5626a94ab97026f3&imgtype=0&src=http%3A%2F%2Fc.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F4bed2e738bd4b31ccda81d7a8bd6277f9f2ff85f.jpg",
        "https://ss3.baidu.com/-fo3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=4b22ec31ddc8a786a12a4c0e5708c9c7/5bafa40f4bfbfbedc5597ab474f0f736aec31ffc.jpg",
        "https://ss3.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=87d6daed02f41bd5c553eef461d881a0/f9198618367adab4b025268587d4b31c8601e47b.jpg",
      ],
    };
  },
  methods: {
    
    
    play() {
    
    
      this.time = setInterval(() => {
    
    
        this.num++;
        if (this.num == 3) {
    
    
          this.num = 0;
        }
      }, 2000);
    },
    change(i) {
    
    
      this.num = i;
    },
    stop() {
    
    
      clearInterval(this.time);
    },
    move() {
    
    
      this.play();
    },
  },
  created() {
    
    
    this.play();
  },
};
</script>

<style>
.wrapper {
    
    
  height: 100%;
  width: 100%;
}
.swiper {
    
    
}
img {
    
    
  width: 100%;
  height: 300px;
}
li {
    
    
  width: 100%;
  height: 300px;
  border: 5px solid white;
  color: white;
  position: absolute;
}
ul {
    
    
  width: 100%;
  height: 300px;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}
.circle {
    
    
  margin-top: 30px;
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, 0);
}
.nav {
    
    
  background-color: #fff;
  color: white;
  margin-right: 10px;
  font-size: 20px;
  display: inline-block;
  width: 33.4px;
  height: 4px;
  opacity: 0.5;
}
.active {
    
    
  opacity: 1;
}

.image-enter {
    
    
  transform: translateX(100%);
}
.image-enter-active {
    
    
  transition: all 1.5s linear;
}
.image-enter-to {
    
    
  transform: translateX(0);
}

.image-leave {
    
    
  transform: translateX(0);
}
.image-leave-active {
    
    
  transition: all 1.5s linear;
}
.image-leave-to {
    
    
  transform: translateX(-100%);
}
</style>

效果如下:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43248623/article/details/110952247