使用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 ...
随机推荐
- appium -- Xpath定位元素
如文章<Appium基于安卓的各种FindElement的控件定位方法实践>所述,Appium拥有众多获取控件的方法.其中一种就是根据控件所在页面的XPATH来定位控件. 本文就是尝试通过 ...
- 面试常问的 25+ 个 Linux 命令
作为一个Java开发人员,有些常用的Linux命令必须掌握.即时平时开发过程中不使用Linux(Unix)或者mac系统,也需要熟练掌握Linux命令.因为很多服务器上都是Linux系统.所以,要和服 ...
- CSP-J 2020题解
CSP-J 2020题解 本次考试还是很有用的,至少把我浇了一盆冷水. 当使用民间数据自测的时候,我就自闭了. 估分是320,但有些比较低级的错误直接少掉80. 而且这套题应该上350才正常吧,也不是 ...
- 干货 MySQL常见的面试题 + 索引原理分析
常见的面试必备之MySQL索引底层原理分析: MySQL索引的本质 MySQL索引的底层原理 MySQL索引的实战经验 面试 1)问题:数据库中最常见的慢查询优化方式是什么? 回答:加索引 2)问题: ...
- mongo命令行操作
- 思维导图VS金字塔原理
作为常识,思维导图制作的核心元素是关键词,而金字塔原理制作的核心元素则是拓展的概要句子,这两种方式是当今人们常用的思维工具,本文对其做了对比,希望对你的选择有所帮助. 金字塔原理结构:从上到下三角形结 ...
- 和功能相近的虚拟机软件相比,CrossOver的产品优势有哪些?
很多用户其实并不喜欢虚拟机软件,他们只是想用回熟悉的Windows应用程序,因为苹果系统与许多软件并不兼容.无奈之下,他们只能安装虚拟机软件.可是虚拟机软件大多比较笨重并且也相对复杂一些,在后期维护上 ...
- C语言讲义——字符串库函数
字符串库函数<string.h> 求字符串长度(不含结束符'\0'****) strlen(str) 字符串赋值(可能造成数组越界) strcpy(str," 水浒传 " ...
- Kafka入门之broker-消息设计
消息设计 1.消息格式 Kafka的实现方式本质上是使用java NIO的ByteBuffer来保存消息,同时依赖文件系统提供的页缓存机制,而非依靠java的堆缓存. 2.版本变迁 0.11.0.0版 ...
- 解决linux挖矿病毒(kdevtmpfsi,sysupdate, networkservice)
突然发现公司测试服务器CPU过高,是这两个sysupdate, networkservice进程,很明显是被挖矿了,记录下来以供参考. 病毒会把一些文件给加i锁或a锁,导致无法修改数据,所以某些操作需 ...