使用Swiper快速实现3D效果轮播
最近经常接到轮播图3D效果的需求, 特在此记录一下以备之后使用。
具体实现效果如下:

在这里介绍两种使用方式, 一种原生的html+php后端渲染, 一种是使用vue。
原生实现
引入
首先我们介绍原生的使用方式,按照swiper官方文档引入swiper.min.css和swiper.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-prev,swiper-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>
效果
实现的效果如下:

使用Swiper快速实现3D效果轮播的更多相关文章
- CSS3,3D效果轮播图
---恢复内容开始--- 大家还记得我昨天的3D拖拽立方体吗??我昨天还说过css还可以做轮播图,所以咱们今天就写一下,css的轮播图吧! ....这个轮播图主要是用CSS3里的transform的旋 ...
- 实现一个3D图片轮播插件 —— 更新版
前言: 前段时间写下了之前那篇 3D图片轮播效果,后来发现了 Pedro Botelho 写的jquery.gallery.js ,于是重新修改了自己的这个图片轮播,使之可以成为一个插件来使用 ...
- 案例:3D切割轮播图
一.3d转换 3D旋转套路:顺着轴的正方向看,顺时针旋转是负角度,逆时针旋转是正角度 二.代码 <!DOCTYPE html> <html lang="en"&g ...
- 带锁的3D切割轮播图
3D切割轮播图. 加入锁,限制点击太快次数 <!DOCTYPE html><html><head lang="en"> <meta cha ...
- 【前端】javascript+jQuery实现旋转木马效果轮播图slider
实现效果: 实现原理: 技术栈: javascript+jQuery+html+css 实现步骤: // 0. 获取元素 // 1. 鼠标放置到轮播图上,显示两侧的控制按钮,移开后隐藏 // 2. 为 ...
- js访3d上下轮播图
js/css访3d上下轮播图 (附件) <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...
- css3实现3D切割轮播图案例
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Swiper 3D flow轮播使用方法
swiper 的3d轮播效果,移动端适用 (1). 如需使用Swiper的3d切换首先加载3D flow插件(js和css). <head> <link rel="styl ...
- android实现3D Gallery 轮播效果,触摸时停止轮播
1.轮播控件涉及到的两个类 CarouselViewPager.java public class CarouselViewPager extends ViewPager { @IntDef({RES ...
随机推荐
- H265Nalu头部解析
一 NALU头部解析 F: 必须为0,为1表示语法错误.整包将被丢弃 NalType:nalu包的类型,其中VCL NAL和non-VCL NAL各有32类.0-31是vcl nal单元:32-63, ...
- [从源码学设计]蚂蚁金服SOFARegistry之程序基本架构
[从源码学设计]蚂蚁金服SOFARegistry之程序基本架构 0x00 摘要 之前我们通过三篇文章初步分析了 MetaServer 的基本架构,MetaServer 这三篇文章为我们接下来的工作做了 ...
- zookeeper和kafka的leader和follower
来源于:https://www.cnblogs.com/aspirant/p/9179045.html 一.zookeeper 与kafka保持数据一致性的不同点: (1)zookeeper使用了ZA ...
- 面试官:小伙子,说一说Java多线程有哪些创建方式吧
第一种 继承Thread类 自定义类,继承Thread类,并重写run()方法. class MyThread1 extends Thread { @Override public void run( ...
- word教程字体和段落设置
放大/缩小字号:1.选中文字-点击"大A"或"小A" 2.同时摁着ctrl+shift+>/ctrl+shift+<即可 设置标题与正文间距:鼠标放 ...
- vulnhub: DC 4
信息收集: yurang@kali:~$ nmap -sn 192.168.76.1/24 Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-04 ...
- thinkphp3.2 添加自定义类似__ROOT__的变量
1 thinkphp3.2 添加自定义类似__ROOT__的变量 2 3 在config.php文件中 4 return array( 5 '' => '', 6 'TMPL_PARSE_STR ...
- Java蓝桥杯练习题——求小数n位后3个数
求整数除法小数点后第n位开始的3位数 位数不足的补0,如0.125小数第3位后三位:0.12500→500 输入格式:a b n,空格分开,a是被除数,b是除数,n是小数后的位置 输出格式:3位数字, ...
- Java数据结构(十)—— 树
树 树的概念和常用术语 常用术语 节点 根节点 父节点 子节点 叶子节点:没有子节点的节点 节点的权:节点的值 路径:节点A到节点B的路径 层 子树 树的高度:最大层数 森林:多颗子树构成森林 二叉树 ...
- Memtest在CentOS下的使用方法。
#memtest,指定测试大小范围248G,指定测试1次 nohup memtester 248G 1 > mem218.log&