当前位置: 首页 > article >正文

vue3 使用swiper制作带缩略图的轮播图

效果图

实现代码
<template>
  <div class="wrap">
    <!-- 主轮播图 -->
    <swiper :style="{
      '--swiper-navigation-color': '#fff',
      '--swiper-pagination-color': '#fff',
    }" :modules="modules" :navigation="true" :thumbs="{ swiper: thumbsSwiper }">
      <SwiperSlide v-for="slide in slides" :key="slide">
        <img style="width: 300px" :src="slide" alt="main slide" />
      </SwiperSlide>
    </swiper>

    <!-- 缩略轮播图 -->
    <swiper @swiper="setThumbsSwiper"
    :spaceBetween="10"
    :slidesPerView="3"
    :freeMode="true"
    :watchSlidesProgress="true"
    :modules="modules"
    class="thumbsSwiper">
      <SwiperSlide v-for="slide in slides" :key="slide">
        <img style="width: 100px" :src="slide" alt="main slide" />
      </SwiperSlide>
    </swiper>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { Swiper, SwiperSlide } from 'swiper/vue';
import { FreeMode, Navigation, Thumbs } from 'swiper/modules';

import 'swiper/css';
import 'swiper/css/free-mode';
import 'swiper/css/navigation';
import 'swiper/css/thumbs';

const slides = ref(['https://temp.im/200x200/4CD964/fff', 'https://temp.im/200x200/999999/fff', 'https://temp.im/200x200/666666/fff', 'https://temp.im/200x200/9696ff/fff','https://temp.im/200x200/696969/fff', 'https://temp.im/200x200/333333/fff']);
const thumbsSwiper = ref(null);
const setThumbsSwiper = (swiper) => {
  thumbsSwiper.value = swiper;
};
const modules = [FreeMode, Navigation, Thumbs];
</script>

<style lang="scss" scoped>
.wrap {
  width: 300px;
  background: #000;
  position: relative;
}
.thumbsSwiper {
  .swiper-slide {
    opacity: 0.4;
  }
  .swiper-slide-thumb-active {
    opacity: 1;
  }
} 
</style>
swiper官网地址

https://swiperjs.com/vue


http://www.kler.cn/news/302878.html

相关文章:

  • 视频笔记1
  • Winform实现弹出定时框功能
  • HarmonyOS开发之(下拉刷新,上拉加载)控件pulltorefresh组件的使用
  • 汽车材料展︱2025 广州国际汽车轻量化技术及车用材料展览会
  • 用Qt 对接‌百度语音识别接口
  • 如何使用studio layout inspector
  • 工具、环境等其他小问题归纳
  • uniapp对tabbar封装,简单好用
  • Unity3d中制作触发区域为圆形的按钮
  • YOLOv5-6.x源码分析----数据集创建之dataloaders.py
  • 【Python 千题 —— 算法篇】寻找最长回文子串
  • JavaWeb【day11】--(SpringBootWeb案例)
  • Android APK插件化:DynamicAPK技术如何改变游戏规则
  • linux安装redis、使用redis、用springboot连接redis
  • DataWind将string类型转化为int类型的报错解决
  • 全国智能网联招标项目一周速览(2024年9月13日)
  • leetcode练习 子集
  • HTML中的零宽字符
  • C# 异步编程中的 SynchronizationContext:掌握上下文同步的艺术
  • 源码编译llama.cpp 、ggml 后端启用自定义BLAS加速
  • 【STM32】独立看门狗(IWDG)原理详解及编程实践(上)
  • [网络][CISCO]CISCO IOS升级
  • 走进低代码表单开发(一):可视化表单数据源设计
  • Redis 入门 - C#|.NET Core客户端库六种选择
  • C++ | Leetcode C++题解之第389题找不同
  • 说真心话,在IT行业,项目经理不懂「敏捷管理」真混不下去!
  • 就服务器而言,ARM架构与X86架构有什么区别?各自的优势在哪里?
  • EP10 全局渐变背景色
  • Android Jetpact Lifecycle 解析
  • STM32双轮平衡小车(基于STM32F103C8T6HAL库)