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>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用vue-awesome-swiper实现缩略图轮播的示例代码: ```html <template> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide" v-for="(item, index) in list" :key="index"> <img :src="item.imgUrl" alt=""> </div> </div> <div class="swiper-pagination"></div> <div class="swiper-scrollbar"></div> <div class="swiper-container thumbnail"> <div class="swiper-wrapper"> <div class="swiper-slide" v-for="(item, index) in list" :key="index"> <img :src="item.imgUrl" alt=""> </div> </div> </div> </div> </template> <script> import 'swiper/css/swiper.css' import { Swiper, Pagination, Scrollbar, Thumbs } from 'swiper/js/swiper.esm' Swiper.use([Pagination, Scrollbar, Thumbs]) export default { data() { return { list: [ { imgUrl: 'https://picsum.photos/id/1018/500/300' }, { imgUrl: 'https://picsum.photos/id/1015/500/300' }, { imgUrl: 'https://picsum.photos/id/1019/500/300' }, { imgUrl: 'https://picsum.photos/id/1020/500/300' }, { imgUrl: 'https://picsum.photos/id/1021/500/300' } ] } }, mounted() { const mySwiper = new Swiper('.swiper-container', { loop: true, pagination: { el: '.swiper-pagination' }, scrollbar: { el: '.swiper-scrollbar' }, thumbs: { swiper: { el: '.thumbnail', slidesPerView: 4, spaceBetween: 10, watchSlidesVisibility: true, watchSlidesProgress: true } } }) } } </script> <style> .thumbnail .swiper-slide { opacity: 0.4; transform: scale(0.5); transition: all 0.3s ease; } .thumbnail .swiper-slide-thumb-active { opacity: 1; transform: scale(1); } </style> ``` 在这个示例中,我们使用了vue-awesome-swiper插件来实现轮播效果,并使用了thumbs选项来实现缩略图轮播。具体来说,我们在Swiper的配置中添加了thumbs选项,并在其中配置了一个新的Swiper实例,用于显示缩略图。我们还通过watchSlidesVisibility和watchSlidesProgress选项来确保缩略图与主轮播图同步。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值