实现swiper 3d 轮播效果

先上个效果图,代码可以直接拿~
image.png

安装swiper和vue-awesome-swiper

因为项目用的是nuxt2,所以考虑到swiper的兼容问题,选择的是"swiper": “^5.2.0”

首先是安装swiper和vue-awesome-swiper,并指定版本

npm install swiper@5.2.0 --savenpm install vue-awesome-swiper@4.1.1 --save

然后引入,在nuxt.config.js中引入

css: ['swiper/css/swiper.css'
],
plugins: [{ src: '@/plugins/vue-swiper', ssr: false }
],

基本用法

在plugins下新建一个vue-swiper.js

import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

在components下新建一个VueSwiper.vue

<template><div v-if="initStatus" v-swiper:mySwiper="swiperOption" class="swiper mySwiper swiperBox"><div class="swiper-wrapper"><div class="swiper-slide" v-for="(item, index) in list.value" :key="index"><div class="pr"><div class="swiper-slide-imgbox uf uf-ac uf-jc"><img :src="item.imageUrl" /></div><div class="font12 c8 txt-box">{{ item.title }}</div></div></div></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>
</template>
<script>
export default {props: {list: {//banner数组type: Object,default: function () {return {}}},slidesPerView: {//一页显示几个type: Number,default: 1}},data() {return {initStatus: false,//初始化状态swiperOption: {},//swiper参数}},mounted() {let self = this;this.$nextTick(() => {this.swiperOption = {loop: true,loopAdditionalSlides: 3,coverflowEffect: {rotate: 60, //侧转角度(正值凹陷)stretch: -80,//每个slide之间拉伸值(正值紧贴)depth: 100,  //值越大为远景(可负值)modifier: 1, //depth和rotate和stretch的倍率shadows: false},centeredSlides: true,initialSlide: 1,slidesPerView: self.slidesPerView,//一页显示几个spaceBetween: 10,//间隔updateOnWindowResize: true,watchSlidesProgress: true,//noSwiping: true,//effect: 'coverflow', //设置Slide的切换效果,默认为"slide"(普通位移切换),还可设置为"fade"(淡入)、"cube"(方块)、"coverflow"(3d流)、"flip"(3d翻转)、"cards"(卡片式)、"creative"(创意性)。freeMode: 1,autoplay: {//自动轮播//delay: 3000, //disableOnInteraction: false,//操作swiper后 自动轮播不会停止//},navigation: {nextEl: '.swiper-button-next',prevEl: '.swiper-button-prev',},}this.initStatus = true //渲染swiper})},
}
</script>
<style lang="scss" scoped>
.swiper {margin-left: auto;margin-right: auto;position: relative;box-sizing: border-box;
}
.swiper-wraper {width: 100%;height: 100%;z-index: 1;display: flex;box-sizing: content-box;
}
.swiper-slide {flex-shrink: 0;width: 100%;height: 100%;
}
.swiper-slide-imgbox{width: 315px;height: 302px;opacity: 1;background: rgba(255, 255, 255, 1);padding: 20px;box-sizing: border-box;
}
.pr{position: relative;
}
.txt-box{position: absolute;bottom: -40px;left: 0;right: 0;margin: 0 auto;
}
</style>

在plugins下引入

// 引入vue 及 组件
import Vue from 'vue'
import VueSwiper from '@/components/VueSwiper'// 全局注册组件
Vue.component('VueSwiper', VueSwiper)

然后是使用这个组件,在pages下新建一个honor.vue

<template><div class="main-container"><PageHeader /><!-- banner --><div class="banner-box"><div class="font48 weight700 c3">资质与荣誉</div><div class="font16 weight400 c7 op7 mt30">Qualifications and Honors</div></div><div class="content-box" v-for="(honorItem, index) in honorTypes" :key="index"><div class="font36 pt100 mb40 vc" v-if="honorInfo[index] && honorInfo[index].value && honorInfo[index].value.length">{{ honorItem.title }}</div><div class="review-content" v-if="honorInfo[index] && honorInfo[index].value && honorInfo[index].value.length"><vue-swiper :list="honorInfo[index]" :slidesPerView="3"></vue-swiper></div></div><PageFooter /></div>
</template><script>
import { shareToWechat } from "../../utils/format";
export default {name: "Honor",data() {return {showType: "honor",honorTypes: [],honors: [],honorInfo: []};},methods:{async findHonorTypeData() {let _params = {order: 'sort'}this.loading = true;const res = await this.$axios.$get("/certType", { params: _params });this.loading = false;let _this = thisif (res && res.status === 0) {this.honorTypes = res.resultres.result.forEach((item, i) => {_this.findHonorsData(item.title)})} else {this.$message.error(res.message);}},async findHonorsData(certType) {let _params = {order: 'sort',certType: certType,pageNum: 1,pageSize: 30}this.loading = true;const res = await this.$axios.$get("/certList", { params: _params });this.loading = false;let _this = thisif (res && res.status === 0) {res.result.rows.forEach((item, i) => {item.imageUrl = `/images${item.imageUrl}`})let _obj = {name: certType,value: res.result.rows}_this.honorInfo.push(_obj)} else {this.$message.error(res.message);}},},mounted () {this.findHonorTypeData()}
};
</script><style lang="scss" scoped>
.content-box{background-color: rgba(239, 241, 244, 1);padding-bottom: 100px;
}
.review-content {width: 100%;height: 302px;position: relative;margin: 0 auto;.swiperBox {height: 360px;width: 100%;position: static;padding-top: 20px;& /deep/ {.swiper-slide {text-align: center;font-size: 18px;background: #fff;width: 315px !important;height: 302px;/* Center slide text vertically */display: -webkit-box;display: -ms-flexbox;display: -webkit-flex;display: flex;-webkit-box-pack: center;-ms-flex-pack: center;-webkit-justify-content: center;justify-content: center;-webkit-box-align: center;-ms-flex-align: center;-webkit-align-items: center;align-items: center;transition-property: all;img {max-width: 295px;height: auto;max-height: 282px;border-radius: 2px;}.swiper-slide-shadow-left{background-image: none}.swiper-slide-shadow-right{background-image: none}}.swiper-slide-active {.mask {display: none;}}.swiper-button-prev,.swiper-button-next {position: absolute;width: 34px;height: 64px;line-height: 64px;border-radius: 6px;font-size:30px;color: #00A2FF;top: 50%;}.swiper-button-prev:after,.swiper-button-next:after {font-size: 30px;&:hover{background-color: none;}}.swiper-button-prev {left: 0px;}.swiper-button-next {right: 0px;}.swiper-button-prev:hover,.swiper-button-next:hover {background: rgba(209, 209, 209, 0.5);color: rgba(255, 255, 255, 0.5);}}}
}
.banner-box {height: 370px;opacity: 1;padding: 172px 120px 0 120px;box-sizing: border-box;background: url(/images/productImages/honor.png) right 120px bottom 20px / 320px auto no-repeat,linear-gradient(90deg, rgba(137, 247, 254, 1) 0%, rgba(84, 156, 252, 1) 100%);;
}
.honor-box {max-width: 990px;padding-bottom: 82px;margin: 0 auto;& .honor-card {width: 300px;margin: 0 15px 48px;box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.16);border-radius: 4px;background-clip: content-box;background-color: rgba(255, 255, 255, 1);background-position: center center;background-size: 100% auto;background-repeat: no-repeat;&.large {padding: 32px;}&.small {padding: 19px 15px;}}
}
@media screen and (max-width: 768px) {.banner-box {height: 260px;background-position: center top 100px, left top;background-size: auto 80px, auto 100%;& .banner-content {top: 260px;width: 100%;}}.honor-box {justify-content: center;padding: 0 30px 20px;& .honor-card {width: 300px;margin: 0 15px 20px;}}
}
</style>

出现空白页的bug

使用了swiper的coverflowEffect效果,设置了同时显示3个,同时开启了loop模式。

当切换到倒数第二张时没有新的slider生成,导致最后一张的右边是空白的,只有切换到最后一张时才会再在后面复制新的slider,怎么让它在显示倒数第二张时就生成新的slider?

image.png

最后发现slidesPerView设置为auto,就正常了

然后调整coverflowEffect里的stretch和depth来弄就没问题了

VueSwiper.vue

<template><div v-if="initStatus" v-swiper:mySwiper="swiperOption" class="swiper mySwiper swiperBox"><div class="swiper-wrapper"><div class="swiper-slide" v-for="(item, index) in list.value" :key="index"><div class="pr"><div class="swiper-slide-imgbox uf uf-ac uf-jc"><img :src="item.imageUrl" /></div><div class="font12 c8 txt-box">{{ item.title }}</div></div></div></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>
</template>
<script>
export default {props: {list: {//banner数组type: Object,default: function () {return {}}}},data() {return {initStatus: false,//初始化状态swiperOption: {},//swiper参数}},mounted() {let self = this;this.$nextTick(() => {this.swiperOption = {loop: true,loopAdditionalSlides: 3,coverflowEffect: {rotate: 50, //侧转角度(正值凹陷)stretch: -110,//每个slide之间拉伸值(正值紧贴)depth: 100,  //值越大为远景(可负值)modifier: 1, //depth和rotate和stretch的倍率shadows: false},centeredSlides: true,initialSlide: 1,slidesPerView: 'auto',//一页显示几个spaceBetween: 10,//间隔updateOnWindowResize: true,watchSlidesProgress: true,//noSwiping: true,//effect: 'coverflow', //设置Slide的切换效果,默认为"slide"(普通位移切换),还可设置为"fade"(淡入)、"cube"(方块)、"coverflow"(3d流)、"flip"(3d翻转)、"cards"(卡片式)、"creative"(创意性)。freeMode: 1,autoplay: {//自动轮播//delay: 3000, //disableOnInteraction: false,//操作swiper后 自动轮播不会停止//},navigation: {nextEl: '.swiper-button-next',prevEl: '.swiper-button-prev',},}this.initStatus = true //渲染swiper})},
}
</script>
<style lang="scss" scoped>
.swiper {margin-left: auto;margin-right: auto;position: relative;box-sizing: border-box;
}
.swiper-wraper {width: 100%;height: 100%;z-index: 1;display: flex;box-sizing: content-box;
}
.swiper-slide {flex-shrink: 0;width: 100%;height: 100%;
}
.swiper-slide-imgbox{width: 315px;height: 302px;opacity: 1;background: rgba(255, 255, 255, 1);padding: 20px;box-sizing: border-box;
}
.pr{position: relative;
}
.txt-box{position: absolute;bottom: -40px;left: 0;right: 0;margin: 0 auto;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/741274.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

conda 解决“libstdc++.so.6: version `GLIBCXX_3.4.20‘ not found“

起因 使用cmake的时候需要调用libstdc.so.6里的GLIBCXX_3.4.20,但是报错 libstdc.so.6: version GLIBCXX_3.4.20’ not found 使用strings命令查看libstdc.so.6里面是否包含GLIBCXX_3.4.20,发现没有&#xff0c;最高到3.4.19版本。需要更新libstdc.so.6&#xff0c;到更高的…

遍历list过程中调用remove方法

1、普通for循环遍历List删除指定元素&#xff0c;list.remove(index) List<String> nameList new ArrayList<>(Arrays.asList("张三", "李四", "王五", "赵六")); nameList.add("张七"); nameList.add("…

基于Unity3D的AVG卡牌游戏设计与实现

目 录 摘 要 I Abstract II 引 言 1 1 相关技术 3 1.1 C# 3 1.2 Unity3D 3 1.3 UGUI 3 1.4 XML 4 1.5 原型设计模式 4 1.6 本章小结 4 2 系统分析 5 2.1 用户需求 5 2.2 功能需求 5 2.3 非功能需求 6 2.4 本章小结 6 3 系统设计 7 3.1 系统该要设计 7 3.2 系统详细设计 7 3.2.…

数组和指针笔试题目解析---掌握他们拿下指针魔鬼

目录 一、前言二、一维数组2.1代码2.2分析2.3验证运行结果 三、字符数组3.1代码13.1.1分析3.1.2验证运行结果 3.2代码23.2.1分析3.2.2验证运行结果 3.3代码33.3.1分析3.3.2验证运行结果 3.4代码43.4.1分析3.4.2验证运行结果 3.5代码53.5.1分析3.5.2验证运行结果 3.6代码63.6.1分…

基于SpringBoot和VUE技术的智慧生活商城系统设计与实现

** &#x1f345;点赞收藏关注 → 私信领取本源代码、数据库&#x1f345; 本人在Java毕业设计领域有多年的经验&#xff0c;陆续会更新更多优质的Java实战项目&#xff0c;希望你能有所收获&#xff0c;少走一些弯路。&#x1f345;关注我不迷路&#x1f345;** 一、研究背景…

Net Core 使用Mongodb操作文件(上传,下载)

Net Core 使用Mongodb操作文件&#xff08;上传&#xff0c;下载&#xff09; 1.Mongodb GridFS 文件操作帮助类。 GridFS 介绍 https://baike.baidu.com/item/GridFS/6342715?fraladdin DLL源码&#xff1a;https://gitee.com/chenjianhua1985/mongodb-client-encapsulati…

C++中的操作符

C中的操作符 :: 在C中&#xff0c;双冒号::被称为作用域解析操作符&#xff08;Scope Resolution Operator&#xff09;。它用于指定一个标识符&#xff08;如变量名、函数名、类型名&#xff09;的作用域。这个操作符主要用于以下几个方面&#xff1a; 1. 访问全局变量 当…

STM32点亮LED灯与蜂鸣器发声

STM32之GPIO GPIO在输出模式时可以控制端口输出高低电平&#xff0c;用以驱动Led蜂鸣器等外设&#xff0c;以及模拟通信协议输出时序等。 输入模式时可以读取端口的高低电平或电压&#xff0c;用于读取按键输入&#xff0c;外接模块电平信号输入&#xff0c;ADC电压采集灯 GP…

论坛管理系统|基于Spring Boot+ Mysql+Java+B/S架构的论坛管理系统设计与实现(可运行源码+数据库+设计文档+部署说明+视频演示)

推荐阅读100套最新项目 最新ssmjava项目文档视频演示可运行源码分享 最新jspjava项目文档视频演示可运行源码分享 最新Spring Boot项目文档视频演示可运行源码分享 目录 目录 前台功能效果图 管理员功能登录前台功能效果图 用户功能模块 系统功能设计 数据库E-R图设计 l…

【WEEK2】学习目标及总结【SpringMVC】【中文版】

学习目标&#xff1a; 三周完成SpringMVC入门——第二周 学习内容&#xff1a; 参考视频教程【狂神说Java】SpringMVC最新教程IDEA版通俗易懂使用注释完成MVC程序Controller控制器RestFul风格结果跳转方式数据处理 学习时间及产出&#xff1a; 第二周 MON~FRI 2024.3.4 【W…

OxyPlot图表曲线图学习笔记(winform)

一、学习OxyPlot 开源地址&#xff1a;https://github.com/oxyplot/oxyplot 最新版&#xff1a;v2.1.2 新建winform&#xff0c;nuget中添加依赖包 二、写代码 2.1 BarSeries 2.2 ScatterSeries 2.3 LineSeries (带指向箭头&#xff09; int pointCount 50; double[] xs …

知识图谱详细建立过程

开始建立知识图谱&#xff1a; 确定知识图谱的范围&#xff1a; 首先&#xff0c;确定你的知识图谱将涵盖的主题范围。樱桃种植涉及到哪些方面&#xff1f;可能包括樱桃的生长周期、品种、栽培技术、土壤和气候要求、病虫害防治、收获和加工等方面。 收集樱桃种植相关的数据&a…

Xilinx 7系列FPGA的配置流程

目录 1.4配置流程 1.4.1 设备上电 ​编辑1.4.2 清除配置寄存器 1.4.3 采样模式引脚 1.4.4 同步 ​编辑1.4.5 检测设备ID ​编辑1.4.6 加载配置数据 1.4.7 CRC校验 1.4.8 启动序列 1.4配置流程 对于所有配置模式&#xff0c;7系列的基本配置流程都是相同的&…

C语言sizeof操作符与strlen函数

1.sizeof与strlen的介绍 (1).sizeof 计算变量的内存空间大小。底层实际上是对变量类型的计算。是一个单目操作符&#xff0c;不是函数&#xff0c;后面的括号可以省略 (2).strlen 函数原型 strlen是一个函数&#xff0c;返回的size_t类型的数据,头文件为string.h计算字符串…

Python爬虫:requests模块的基本使用

学习目标&#xff1a; 了解 requests模块的介绍掌握 requests的基本使用掌握 response常见的属性掌握 requests.text和content的区别掌握 解决网页的解码问题掌握 requests模块发送带headers的请求掌握 requests模块发送带参数的get请求 1 为什么要重点学习requests模块&…

关于k8s中 storageclass 的 is-default-sc 默认存储设置

为什么要改变默认存储类&#xff1f; 取决于安装模式&#xff0c;你的 Kubernetes 集群可能和一个被标记为默认的已有 StorageClass 一起部署。 这个默认的 StorageClass 以后将被用于动态的为没有特定存储类需求的 PersistentVolumeClaims 配置存储。更多细节请查看 Persiste…

MySQL—InnoDB在RC隔离级别下如何处理事务读取操作

本文将探讨InnoDB在读已提交&#xff08;Read Committed&#xff09;隔离级别下如何处理事务读取操作的原理。这个过程是InnoDB多版本并发控制&#xff08;MVCC&#xff09;机制的一个关键组成部分&#xff0c;旨在提供高效的事务隔离&#xff0c;同时减少锁的需求&#xff0c;…

如何在安卓端的SAP里配置打印机

1、转到 SPAD 事务&#xff08;“假脱机管理”屏幕&#xff09;。单击“设备/服务器”选项卡&#xff0c;输入输出设备的名称&#xff0c;然后点击显示按钮。 2、如果打印机已配置&#xff0c;它将显示设备属性、输出设备属性和纸盒信息的所有详细信息。如果输入新的打印机名称…

AndroidStudio设计登录页源码(音悦app)

目录 一、代码 二、效果 一、代码 1.在activity_main.xml里的代码 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent&quo…

import gdal 报错

1.下载gdal https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal 2.安装正确版本 &#xff08;1&#xff09;查看python版本 python -v我的版本Python 3.7.9 建议下载 GDAL-3.4.2-cp37-cp37m-win_amd64.whl &#xff08;2&#xff09;放到Scripts文件夹下 执行 pip install GD…