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

实现异形(拱形)轮播图

项目需要实现如上图所示的轮播图。
实现思路:
1.项目引入使用普通轮播图。
2.根据轮播图个数,动态给可视范围的第一个轮播图和最后一个轮播图添加样式。
代码实现:
经调研,使用slick轮播图(官网地址  https://kenwheeler.github.io/slick/)
1.点击下载插件包

将其放到staic文件夹下,在vue项目中,index.html文件中引入js和css。

注意:还需要额外引入jquery。
2.页面使用。
html:

<div id="autoplayClass1"><div :class="['slideItemWrapper', 'slideItemWrapper'+index , 'slideItemWrapperCenter']" v-for="(item,index) in lunbo1List"  :key="index"   :title="item.fileName"><img :src="hAction + item.filePath" class="inage  inagex" /></div></div>

lunbo1List为后端返回的图片列表。
js:

 autoPlaySlide(){//slideItemWrapperFirst为第一个轮播图的样式,slideItemWrapperLast为最后一个轮播图的样式。//slideItemWrapperCenter为默认轮播图样式$(".slideItemWrapper0").addClass('slideItemWrapperFirst')$(".slideItemWrapper4").addClass('slideItemWrapperLast')//轮播设置$('#autoplayClass1').slick({slidesToShow: 5,    slidesToScroll: 1,  //每次轮播个数autoplay: true,autoplaySpeed: 2000,});//轮播change时,样式动态添加      $('#autoplayClass1').on('beforeChange', function (event, slick, currentSlide, nextSlide) {$('.slideItemWrapper' + nextSlide).removeClass('slideItemWrapperCenter')$('.slideItemWrapper' + nextSlide).addClass('slideItemWrapperFirst')let lastRotate = nextSlide + 4if (lastRotate > lunboList.length-1) {lastRotate = lastRotate - lunboList.length}$('.slideItemWrapper' + lastRotate).removeClass('slideItemWrapperCenter')$(".slideItemWrapper" + lastRotate).addClass('slideItemWrapperLast')$(".slideItemWrapper" + currentSlide).removeClass('slideItemWrapperFirst')$('.slideItemWrapper' + currentSlide).addClass('slideItemWrapperCenter')let lastRotatel = currentSlide + 4if (lastRotatel > lunboList.length-1) {lastRotatel = lastRotatel - lunboList.length}$(".slideItemWrapper" + lastRotatel).removeClass('slideItemWrapperLast')$('.slideItemWrapper' + lastRotatel).addClass('slideItemWrapperCenter')});},

css:实现异性样式

   //最左侧图片形状处理.slideItemWrapperFirst {position: relative;width: 17vw;/* 或你需要的宽度 */height: 20vh;/* 或你需要的高度 */display: inline-block;}.slideItemWrapperFirst::after {content: '';position: absolute;top: 0;left: 0;width: 100%;height: 100%;//   background: white; /* 这是图片背景色,根据实际情况调整 */z-index: 1;}.slideItemWrapperFirst img {width: 14.6;height: 15.5vh;position: relative;z-index: 2;}.slideItemWrapperFirst img {clip-path: polygon(0 0, calc(100%) 0, calc(100%) calc(100% - 3.5vh), 0 calc(100%));/* 10px 是缺失角的宽度,根据需求调整 */}//最右侧图片形状处理.slideItemWrapperLast {position: relative;width: 17vw;height: 20vh;display: inline-block;}.slideItemWrapperLast::after {content: '';position: absolute;top: 0;left: 0;width: 100%;height: 100%;//   background: white; /* 这是图片背景色,根据实际情况调整 */z-index: 1;}.slideItemWrapperLast img {width: 14.6;height: 15.5vh;position: relative;z-index: 2;}//关键代码clip-path::.slideItemWrapperLast img {clip-path: polygon(0 0, 100% 0, 100% 100%, 0 calc(100% - 3.5vh));/* 10px 是缺失角的宽度,根据需求调整 */}

如何页面有多个轮播图同时使用,需要销毁的话:
 $('#autoplayClass1').slick('unslick')

http://www.lryc.cn/news/427423.html

相关文章:

  • 【软件测试】2024年职业院校技能大赛高职组“软件测试”赛项样题
  • python数组和队列
  • Vision Transformer(ViT)一种将Transformer架构应用于计算机视觉领域的模型
  • 得到任务式 大模型应用开发学习方案
  • 使用el-menu跳转时偶尔会出现路由已经变了,但是页面却显示空白的情况
  • C语言家教记录(七)
  • 【数据结构】——十大排序详解分析及对比
  • 散点图适用于什么数据 thinkcell散点图设置不同颜色
  • 1. windows搭建Kafka教程
  • XSS复现
  • 怎么利用XML发送视频彩信
  • 5G+工业互联网产教融合创新实训室解决方案
  • 象棋布局笔记
  • 百度AI智能云依赖库OpenSSL库和Curl库及jsoncpp库安装
  • 智慧空调离线语音控制方案:NRK3301芯片的深度解析与应用
  • 基础第3关:LangGPT结构化提示词编写实践
  • Nginx系列-负载均衡
  • 中职物联网实训室
  • Image-coloring的部署,在Ubuntu22.04系统下——点动科技
  • Springboot 整合 Swagger3(springdoc-openapi)
  • netty4报错:io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
  • 2022年汽车软件行业产业细分及发展趋势分析
  • 如何通过变更让 PostgreSQL 翻车
  • MySQL表涉及规范
  • 服务器Ubuntu22.04系统 使用dcocker部署安装ollama和搭配open_webui使用
  • 代理模式Proxy
  • C++ 设计模式——抽象工厂模式
  • 《亿级流量系统架构设计与实战》第十一章 Timeline Feed服务
  • 氙灯老化试验箱试验机
  • 【Qt】常用控件QRadioButton