最近经常接到轮播图3D效果的需求, 特在此记录一下以备之后使用。

具体实现效果如下:

在这里介绍两种使用方式, 一种原生的html+php后端渲染, 一种是使用vue。

原生实现

引入

首先我们介绍原生的使用方式,按照swiper官方文档引入swiper.min.cssswiper.min.js

<link href="https://cdn.bootcdn.net/ajax/libs/Swiper/5.3.1/css/swiper.min.css" rel="stylesheet">
<script src="https://cdn.bootcdn.net/ajax/libs/Swiper/5.3.1/js/swiper.min.js"></script>

html结构

html结构如下:

<!--教师介绍-->
<div class="jieshao">
<div class="swiper-container2">
<div class="swiper-wrapper">
{volist name="teacherInfo" id="vo"}
<div class="swiper-slide">
<img class="swiper-img" src="__CDN__{$vo.image}" alt="" />
<div class="lay-pop">
<div class="lay-pop-box">
</div>
<div class="title">
{$vo.name}
</div>
<div class="desc">
{$vo.description}
</div>
</div>
</div>
{/volist}
</div>
</div>
</div>

css结构

css结构如下:

.jieshao{
width: 1080px;
height: 551px;
margin: auto;
overflow: hidden;
}
.swiper-slide{
box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.05);
border-radius: 26px;
position: relative;
height: 551px;
}
.swiper-img{
position: absolute;
width: 100%;
height: 551px;
border-radius: 26px;
}
.lay-pop{
color: #fff;
position: absolute;
bottom: 0;
left: 0;
right: 0;
overflow: hidden;
}
.lay-pop-box{
position: absolute;
width: 100%;
height: 100%;
background: #000000;
border-radius: 26px;
opacity: 0.18;
}
.lay-pop .title{
color: #fff;
font-size: 30px;
font-weight: bold;
padding: 25px 30px 14px 40px;
position: relative;
z-index: 1;
}
.lay-pop .desc{
width: 100%;
height: 112px;
font-size: 12px;
font-weight: 400;
padding: 0 30px 10px 40px;
margin-bottom: 24px;
color: #fff;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
overflow: hidden;
word-break:break-all;
position: relative;
z-index: 1;
}
.swiper-slide-prev {
transform: scale(0.9);
opacity: 0.3; }
.swiper-slide-next {
transform: scale(0.9);
opacity: 0.3;
} .swiper-slide .lay-pop{
display: none;
}
.swiper-slide-active .lay-pop{
display: block;
}

js结构

js结构如下:

var mySwiper = new Swiper ('.swiper-container2', {
autoplay: {
delay: 3000,
disableOnInteraction: false,
},
slidesPerView: 3,
spaceBetween: 2,
centeredSlides: true,
centeredSlidesBounds: true,
observer: true, //修改swiper自己或子元素时,自动初始化swiper
observeParents: true, //修改swiper的父元素时,自动初始化swiper
loop: true,
})

主要通过slidesPerView设置需要显示轮播的数量,并通过swiper-slide-prevswiper-slide-next两个类名对上一张下一张轮播进行缩小, 达到中间大而两边小的效果。

Vue实现

vue使用中还是有几个小坑的,需要大家注意一下。

安装

首先安装Swiper包npm i swiper

引入

我目前安装的最新版Swiper是6.3.5版的, 如果是6.x的版本在这里务必要注意如果需要分页器以及自动轮播都是需要引入对应在Swiper里的组件的。

import 'swiper/swiper-bundle.css'
import Swiper, { Pagination, Navigation, Autoplay } from 'swiper';
Swiper.use([Pagination, Navigation, Autoplay]);

具体使用

<div v-if="images.length" class="banner">
<swiper ref="mySwiper" :options="swiperOptions">
<swiper-slide v-for="item of images" :key="item.id">
<img class="banner-image" :src="item.image" alt="" />
<!-- <div class="title">{{ image }}</div> -->
</swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
</div>

swiperOptions配置:

swiperOptions: {
pagination: {
el: ".swiper-pagination",
},
autoplay: {
delay: 3000,
disableOnInteraction: false,
},
effect: "coverflow",
slidesPerView: 1.2,
spaceBetween: 2,
loopedSlides: 5,
centeredSlides: true,
centeredSlidesBounds: true,
observer: true, //修改swiper自己或子元素时,自动初始化swiper
observeParents: true, //修改swiper的父元素时,自动初始化swiper
loop: true,
},
<style lang="scss">
.home {
.swiper-slide {
width: 340px;
background-color: #ebedf0;
border-radius: 6px;
.banner-image {
border-radius: 6px;
}
}
.swiper-slide-prev {
transform: scale(0.9);
}
.swiper-slide-next {
transform: scale(0.9);
} .swiper-container {
--swiper-theme-color: #fff;
}
.swiper-pagination.swiper-pagination-bullets {
width: auto;
right: 60px;
text-align: right;
}
.swiper-pagination-bullet {
width: 6px;
height: 6px;
background: #FFFFFF;
border-radius: 4px;
}
.swiper-pagination-bullet-active {
width: 20px;
height: 6px;
border-radius: 5px;
}
}
</style>

效果

实现的效果如下:

最新文章

  1. ReactNative 分享解决listView的一个郁闷BUG
  2. QTableWidget行选中/删除/添加行
  3. Ajax.BeginForm参数详解
  4. Python3学习(一)-基础、数据类型、变量、字符串和编码、list&amp;tuple、if、for、while、dict、set、函数与参数
  5. XML数据 JSON数据 LitJSON 数据 的编写和解析 小结
  6. UI学习之常用方法(续)
  7. mysql 慢查询日志记录
  8. 设计模式总结篇系列:观察者模式(Observer)
  9. RouterOS软路由常用命令
  10. 用Vmware安装centos5
  11. 对Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架的个人认识
  12. MLC固态硬盘,与入量是3000次P/E
  13. Virtual Environments
  14. HTML5学习摘录
  15. Android开发----------- 手电筒改进版本号
  16. 读书笔记 effective c++ Item 46 如果想进行类型转换,在模板内部定义非成员函数
  17. Oracle Windows安装图解
  18. 图像转化成TFrecords格式并回转
  19. jQuery实现的3个基础案例(仿QQ列表分组,二级联动下拉框,模拟员工信息管理系统)
  20. 【Python】【内置函数】【bytes&amp;bytearray&amp;str&amp;array】

热门文章

  1. hmac检验客户端合法性
  2. win10,ubuntu时间不对问题
  3. metasploit数据库使用学习
  4. webug第六关:这关需要rmb购买哦
  5. 记一次容器内执行ansible命令卡住
  6. vue中父子间传值和非父子间传值
  7. 思维导图iMindMap可以在哪些领域应用
  8. 苹果电脑下载电影教程:如何用folx下载《小妇人》
  9. centons 7 清机 脚本
  10. Python正则表达式大全