Swiper 大图,小图联动轮播例子

时间: 2024-02-05 20:02:48 浏览: 28
下面是一个使用 Swiper 实现大图和小图联动轮播的例子,你可以根据自己的需求进行修改和定制: HTML 代码: ```html <div class="swiper-container big-swiper"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="big-image-1.jpg" alt="Big Image 1"> </div> <div class="swiper-slide"> <img src="big-image-2.jpg" alt="Big Image 2"> </div> <div class="swiper-slide"> <img src="big-image-3.jpg" alt="Big Image 3"> </div> </div> <div class="swiper-pagination"></div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> <div class="swiper-container small-swiper"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="small-image-1.jpg" alt="Small Image 1"> </div> <div class="swiper-slide"> <img src="small-image-2.jpg" alt="Small Image 2"> </div> <div class="swiper-slide"> <img src="small-image-3.jpg" alt="Small Image 3"> </div> </div> </div> ``` CSS 代码: ```css .swiper-slide img { width: 100%; height: auto; } .swiper-container { width: 100%; height: 100%; } .big-swiper { position: relative; } .swiper-pagination { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); } .swiper-button-prev, .swiper-button-next { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; background-color: rgba(0, 0, 0, 0.5); border-radius: 50%; color: #fff; font-size: 20px; line-height: 40px; text-align: center; cursor: pointer; } .swiper-button-prev { left: 10px; } .swiper-button-next { right: 10px; } .small-swiper { margin-top: 10px; } .small-swiper .swiper-slide { width: 100px; height: 60px; margin-right: 10px; } .small-swiper .swiper-slide:last-child { margin-right: 0; } .small-swiper img { width: 100%; height: 100%; cursor: pointer; opacity: 0.5; } .small-swiper .swiper-slide-active img { opacity: 1; } ``` JavaScript 代码: ```javascript var bigSwiper = new Swiper('.big-swiper', { loop: true, autoplay: { delay: 3000, disableOnInteraction: false }, pagination: { el: '.swiper-pagination', clickable: true }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } }); var smallSwiper = new Swiper('.small-swiper', { slidesPerView: 3, spaceBetween: 10, freeMode: true, watchSlidesVisibility: true, watchSlidesProgress: true, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } }); bigSwiper.controller.control = smallSwiper; smallSwiper.controller.control = bigSwiper; smallSwiper.on('click', function() { bigSwiper.slideTo(smallSwiper.clickedIndex); }); ``` 在上面的例子中,我们使用了两个 Swiper 实例,一个用于显示大图,另一个用于显示小图。我们通过 bigSwiper.controller.control = smallSwiper; 和 smallSwiper.controller.control = bigSwiper; 来实现大图和小图的联动效果。在小图中点击某一张图片时,我们通过 smallSwiper.on('click', function() {}); 来跳转到对应的大图。

相关推荐

最新推荐

recommend-type

swiper 自动图片无限轮播实现代码

今天移动端正好需要图片触摸滑动效果实现代码,基于swiper实现,需要的朋友可以参考下
recommend-type

swiper移动端轮播插件(触碰图片之后停止轮播)

主要为大家详细介绍了swiper移动端轮播插件,触碰图片之后停止轮播,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

微信小程序实战之轮播图(3)

轮播图是大部分应用的一个常用的功能,常用于广告投放、产品展示、活动展示等等。 漂亮的轮播图效果可以吸引用户的点击,达到推广产品的作用。 废话少说,下面开始动手。 业务需求: 5个图片轮番播放,可以左右...
recommend-type

vue轮播图插件vue-awesome-swiper的使用代码实例

本篇文章主要介绍了vue轮播图插件vue-awesome-swiper的使用代码实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

vue中引用swiper轮播插件的教程详解

主要介绍了vue中引用swiper轮播插件的方法,在需要使用swiper的组件里引入swiper,swiper的初始化放在mounted里。具体实例代码大家跟随脚本之家小编一起看看吧
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB取整函数与Web开发的作用:round、fix、floor、ceil在Web开发中的应用

![MATLAB取整函数与Web开发的作用:round、fix、floor、ceil在Web开发中的应用](https://img-blog.csdnimg.cn/2020050917173284.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2thbmdqaWVsZWFybmluZw==,size_16,color_FFFFFF,t_70) # 1. MATLAB取整函数概述** MATLAB取整函数是一组强大的工具,用于对数值进行
recommend-type

我想做python的算法工程师,我应该学什么?学习的顺序是什么?网上有什么推荐的免费课程吗?回答具体精确一点不要太笼统

对于想要成为 Python 算法工程师的人来说,他们应该先从掌握 Python 的基础语法开始,然后学习数据结构和算法,并且要深入了解 Python 中的一些科学计算和数据处理库,比如 NumPy、Pandas 等。 学习的顺序可以是先学习基础语法和编程技巧,然后再学习数据结构和算法相关的知识,最后深入了解数据处理和科学计算相关的库。 对于免费课程的推荐,我建议你可以先去 Coursera、edX、Udacity 等网站上寻找相关课程,这些网站上有很多优质的 Python 编程和算法课程,你可以根据自己的需求和学习进度进行选择。此外,还可以考虑一些在线编程网站,如 HackerRank、L
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。