css缩略图轮播

<template>
  <div class="container">
    <div class="big-box">
      <img :src="`src/assets/temp/${bigImageSrc}`"/>
    </div>

    <div class="small-box">
      <div class="img" v-for="imgUrl in imageSrcs" @mouseover="changeBigImage(imgUrl)" @mouseleave="startTimer">
        <img :src="`src/assets/temp/${imgUrl}`">
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      bigImageSrc: '1.jpg', // 默认大图地址
      imageSrcs: [ // 小图地址列表
        '1.jpg',
        '2.jpg',
        '3.jpg',
        '4.jpg',
        '5.jpg',
      ],
      count: 0,
      timer: null,
    }
  },
  created() {

  },
  methods: {
    changeBigImage(src) {
      clearInterval(this.timer);
      this.timer = null;
      this.bigImageSrc = src;
    },
    startTimer() {
      this.timer = setInterval(() => {
        if (this.count === 5) {
          this.count = 0;
        }
        this.count++;
        this.bigImageSrc = this.count + ".jpg"
      }, 2000); // 每秒执行一次
    },
  },
  mounted() {
    this.startTimer()
  },
};
</script>

<style scoped>
.container {
  padding: 50px 20vw;
  /* 每个元素之间的间隔相等 */
  justify-content: space-evenly;
  /* 溢出隐藏 */
  text-align: center;
}

.big-box {
  display: flex;
  width: 100%;
  height: 70vh;
  background-size: cover;
}

.small-box {
  margin-top: 10px;
  width: 100%;
  /* 弹性布局 垂直排列 均匀排列每个元素 */
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.small-box .img {
  width: 10vw;
  height: 12vh;
  transition: 0.5s;
}

.small-box .img img {
  width: 10vw;
  height: 12vh;
  /* 保持原有尺寸比例,裁切长边 */
  object-fit: cover;
  /* 设置过渡 */
  transition: 0.7s;
}

.small-box .img:hover img {
  border: 10px white solid;
}
</style>

相关推荐

  1. 白学的小知识[css3]

    2024-04-29 14:46:04       33 阅读
  2. CSS实现首尾相接的无限效果

    2024-04-29 14:46:04       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-29 14:46:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-29 14:46:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-29 14:46:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-29 14:46:04       18 阅读

热门阅读

  1. Vue.js(过渡)

    2024-04-29 14:46:04       11 阅读
  2. Linux内核驱动开发-001字符设备开发-002led杂项驱动

    2024-04-29 14:46:04       10 阅读
  3. Stylus入门使用方法

    2024-04-29 14:46:04       12 阅读
  4. UKP3D轴侧图出图按照哪些标准

    2024-04-29 14:46:04       8 阅读
  5. 在docker中安装paddle serving @FreeBSD(待续)

    2024-04-29 14:46:04       9 阅读
  6. c++课堂——动态规划

    2024-04-29 14:46:04       13 阅读
  7. 【排序算法】快速排序

    2024-04-29 14:46:04       11 阅读