vue2+swiper——实现多图轮播+层叠轮播——技能提升

news2024/9/20 18:53:05

今天看到同事在写轮播图,由于是jq的写法,我没有过多参与,我只写vue的部分。。。虽然语言不一样,但是用法还是要会的。下面介绍通过swiper组件来实现轮播效果。

解决步骤1:安装swiper

npm install swiper@5.4.5
我这边安装的版本是5.4.5

解决步骤2:在指定页面中局部注册

import Swiper from 'swiper'; // 注意引入的是Swiper
import 'swiper/css/swiper.min.css'; // 注意这里的引入

解决步骤3:多图轮播效果

在这里插入图片描述
参考链接:https://blog.csdn.net/qq_51055690/article/details/132402936

3.1html代码

 <div class="banshi">
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div
            v-for="item in swiperList"
            :key="item.id"
            class="swiper-slide"
            :style="`background-image:url(${item.imgUrl})`"
          >
            <h3>{{ item.title }}</h3>
            <el-button>立即办理</el-button>
          </div>
        </div>
        <div class="swiper-pagination"></div>
        <div class="swiper-button-next"></div>
        <div class="swiper-button-prev"></div>
      </div>
    </div>

3.2 js代码

swiper: null,
swiperList: [
 {
   id: 1,
   title: '采集国家二级保护野生植物审批',
   imgUrl:
     'https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500',
 },
 {
   id: 2,
   title: '农村危房改造',
   imgUrl:
     'https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500',
 },
 {
   id: 3,
   title: '农村危房改造',
   imgUrl:
     'https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500',
 },
 {
   id: 4,
   title: '农村危房改造',
   imgUrl:
     'https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500',
 },
],

3.3 methods方法

getSwiper() {
   this.swiper = new Swiper('.swiper-container', {
     loop: true, // 无缝
        autoplay: { //自动开始
            delay: 3000, //时间间隔
            disableOnInteraction: false, //*手动操作轮播图后不会暂停*
        },
        paginationClickable: true,
        slidesPerView: 4, // 一组三个
        spaceBetween: 30, // 间隔
        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        // 窗口变化,重新init,针对F11全屏和放大缩小,必须加
        observer: true,
        observeParents: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
            clickable: true, // 分页器可以点击
        }, 
    });
 },

此方法要在mounted中使用:

mounted() {
  this.getSwiper();
},

3.4 css样式

<style lang="less">
.banshi {
  width: 1200px;
  margin: 0 auto;
  padding: 70px 0;
  .swiper-slide {
    position: relative;
    height: 328px;
    width: 264px;
    padding: 36px 22px;
    background-repeat: no-repeat;
    background-size: contain;
    background-color: #f7f8fa;
    .el-button {
      z-index: 2;
    }
  }
}
</style>

解决步骤4:层叠轮播效果

在这里插入图片描述
参考链接:https://www.cnblogs.com/a973692898/p/13364563.html

4.1 html代码

<div class="ours-main">
      <div class="ours-swiper">
        <div class="swiper-container">
          <div class="swiper-wrapper">
            <div class="swiper-slide">
              <div class="s-left">
                <div class="s-l-block">
                  <img
                    src="https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500"
                  />
                </div>
              </div>
              <div class="s-right">
                <div class="s-r-title">
                  <span>外教abcd</span>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div class="s-left">
                <div class="s-l-block">
                  <img
                    src="https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500"
                  />
                </div>
              </div>
              <div class="s-right">
                <div class="s-r-title">
                  <span>外教abcd</span>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div class="s-left">
                <div class="s-l-block">
                  <img
                    src="https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500"
                  />
                </div>
                 
              </div>
              <div class="s-right">
                <div class="s-r-title">
                  <span>外教abcd</span>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div class="s-left">
                <div class="s-l-block">
                  <img
                    src="https://img0.baidu.com/it/u=2639758887,1655012884&fm=253&fmt=auto&app=138&f=PNG?w=632&h=500"
                  />
                </div>
              </div>
              <div class="s-right">
                <div class="s-r-title">
                  <span>外教abcd</span>
                </div>
              </div>
            </div>
          </div>
          <div class="swiper-pagination"></div>
          <!-- Add Arrows -->
          <div class="swiper-button-next swiper-button-black"></div>
          <div class="swiper-button-prev swiper-button-black"></div>
        </div>
      </div>
    </div>

4.2 methods方法

getSwiper() {
  var swiper = new Swiper('.swiper-container', {
    slidesPerView: 1.5, //设置slider容器能够同时显示的slides数量(carousel模式)。
    spaceBetween: -180, //在slide之间设置距离(单位px)。
    centeredSlides: true, //设置活动块居中
    loop: true,
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
    },
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    autoplay: {
      stopOnLastSlide: true,
      delay: 5000,
    },
  });
},

此方法要在mounted中使用:

mounted() {
  this.getSwiper();
},

4.3 css样式

<style scoped lang="less">
/*展示区域*/
.ours-main {
  width: 100%;
  height: 28rem;
  margin-top: 3rem;
  display: flex;
  justify-content: center;
}
.ours-swiper {
  height: 100%;
  width: 49.8%;
}
/*自定义swiper样式*/
.swiper-container {
  position: relative;
  width: 100%;
  height: 100%;
}
.swiper-wrapper {
  width: 100%;
  height: 100%;
}
.swiper-slide {
  text-align: center;
  height: 86%;
  background: #cccdce;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: 300ms;
  transform: scale(0.8);
}

.swiper-slide-active,
.swiper-slide-duplicate-active {
  transform: scale(1);
}
.swiper-button-next,
.swiper-button-prev {
  display: block;
}
.swiper-slide-active {
  z-index: 999 !important;
}
.swiper-slide-prev .s-right {
  display: none;
}
.swiper-slide-prev .s-left {
  margin-left: 35%;
}
.swiper-slide-prev {
  background-color: #fff;
}
.swiper-slide-next {
  background-color: #fff;
}
/*要展示的div左侧样式*/
.s-left {
  width: 50%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.s-l-block {
  width: 92.2%;
  height: 85%;
}
.s-l-block img {
  width: 100%;
  height: 100%;
}
/*要展示div的右侧样式*/
.s-right {
  width: 45%;
  height: 100%;
}
.s-r-title {
  margin-top: 2rem;
  margin-right: 10%;
  font-size: 2rem;
  color: #676769;
  font-weight: 500;
}
</style>

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

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

相关文章

数据分享—全国分省河流水系

河流水系数据是日常研究中必备的数据之一&#xff0c;本期推文主要分享全国分省份的水系和河流数据&#xff0c;梧桐君会不定期的更新数据&#xff0c;欢迎长期订阅。 数据预览 山东省河流水系 吉林省河流水系 四川省河流水系 数据获取方式 链接&#xff1a;https://pan.baidu.…

基于阿里云向量检索 Milvus 版与 PAI 搭建高效的检索增强生成(RAG)系统

阿里云向量检索 Milvus 版现已无缝集成于阿里云 PAI 平台&#xff0c;一站式赋能用户构建高性能的检索增强生成&#xff08;RAG&#xff09;系统。您可以利用 Milvus 作为向量数据的实时存储与检索核心&#xff0c;高效结合 PAI 和 LangChain 技术栈&#xff0c;实现从理论到实…

网络基础(三)——网络层

目录 IP协议 1、基本概念 2、协议头格式 2.1、报头和载荷如何有效分离 2.2、如果超过了MAC的规定&#xff0c;IP应该如何做呢&#xff1f; 2.3、分片会有什么影响 3、网段划分 4、特殊的ip地址 5、ip地址的数量限制 6、私有ip地址和公网ip地址 7、路由 IP协议 网络…

LINUX 精通 1——2.1.1 网络io与io多路复用select/poll/epoll

LINUX 精通 1 day12 20240509 算法刷题&#xff1a; 2道高精度 耗时 107min 课程补20240430 耗时&#xff1a;99 min day 13 20240512 耗时&#xff1a;200min 课程链接地址 前言 杂 工作5-10年 够用 费曼&#xff1a;不要直接抄&#xff0c;自己写&#xff1b;不要一个…

【微服务】spring aop实现接口参数变更前后对比和日志记录

目录 一、前言 二、spring aop概述 2.1 什么是spring aop 2.2 spring aop特点 2.3 spring aop应用场景 三、spring aop处理通用日志场景 3.1 系统日志类型 3.2 微服务场景下通用日志记录解决方案 3.2.1 手动记录 3.2.2 异步队列es 3.2.3 使用过滤器或拦截器 3.2.4 使…

安全工程师面试题

安全工程师面试题安全工程师是一个非常重要的职位&#xff0c;他们负责保护公司的网络和系统免受黑客和恶意软件的攻击。如果你想成为一名安全工程师&#xff0c;那么你需要准备好面试。下面是一… 1安全工程师面试题 安全工程师是一个非常重要的职位&#xff0c;他们负责保护…

【全开源】Java俱乐部系统社区论坛商城系统源码-奔驰奥迪保时捷大众宝马等汽车俱乐部

特色功能&#xff1a; 会员中心&#xff1a;会员中心可以帮助企业更好地管理客户&#xff0c;包括设置积分商城、会员卡充值、个人汽车档案等功能&#xff0c;对不同的会员群体展开有针对性的营销&#xff0c;并维护和积累自己的粉丝群体。信息服务&#xff1a;负责定期发布新…

后端项目开发笔记

Maven打包与JDK版本不对应解决方法 我这里使用jdk8。 <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configurat…

【Docker】Ubunru下Docker的基本使用方法与常用命令总结

【Docker】docker的基本使用方法 镜像image与容器container的关系基本命令- 查看 Docker 版本- 拉取镜像- 查看系统中的镜像- 删除某个镜像- 列出当前 Docker 主机上的所有容器&#xff0c;包括正在运行的、暂停的、已停止的&#xff0c;以及未运行的容器- 列出当前 Docker 主机…

day05-面向对象内存原理和数组

day05 面向对象内存原理和数组 我们在之前已经学习过创建对象了,那么在底层中他是如何运行的。 1.对象内存图 1.1 Java 内存分配 Java 程序在运行时&#xff0c;需要在内存中分配空间。为了提高运算效率&#xff0c;就对空间进行了不同区域的划分&#xff0c;因为每一片区域…

leetcode——反转链表

206. 反转链表 - 力扣&#xff08;LeetCode&#xff09; 思路&#xff1a;创建三个指针n1,n2,n3&#xff0c;遍历原链表&#xff0c;通过三者之间的关系将链表反转。下面给出图示&#xff1a; 下面给出题解代码&#xff1a; typedef struct ListNode ListNode; struct List…

C++入门指南(上)

目录 ​编辑 一、祖师爷画像 二、什么是C 三、C发展史 四、C在工作领域的应用 1. 操作系统以及大型系统软件开发 2. 服务器端开发 3. 游戏开发 4. 嵌入式和物联网领域 5. 数字图像处理 6. 人工智能 7. 分布式应用 五、如何快速上手C 一、祖师爷画像 本贾尼斯特劳斯…

vmware虚拟机内删除文件后宿主机空间不释放

问题描述 linux下&#xff0c;vmware内虚拟机删除文件&#xff0c;宿主机空间不释放&#xff0c;D盘快满了 解决方法 通过vmware-toolbox进行空间回收 安装 在虚拟机内操作 yum install -y open-vm-tools 清理 在虚拟机内操作 #查看磁盘的挂载点 sudo /usr/bin/vmware…

设计模式-结构型-桥接模式-Bridge

桥接模式可以减少类的创建 矩阵类 public class Matrix {private String fileName;public Matrix(String fileName) {this.fileName fileName;}public String getFileName() {return fileName;} } 图片抽象类 public abstract class Image {protected ImageImp imp;public …

C#二维数组(矩阵)求伴随矩阵和逆矩阵

程序框架及winform窗体 窗体控件: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace Matrix {internal class Algorithm_Gallery{// <summary>/// 计算 A[p,q] 位于 [,]temp 的块辅因子…

Oracle数据库之 常用数据库对象(二)

目录 1.视图 1.1.什么是视图&#xff1f; 1.2.创建视图的语法 1.3.简单视图和复杂视图 1.4.创建复杂视图 1.4.1.创建复杂视图的步骤 1.4.2.示例 1.4.3.注意事项 1.5.视图中使用DML的规定 1.5.1.屏蔽DML操作 1.6.删除视图 2.序列 2.1.语法&#xff1a; 2.2.查询序…

【AI源码】音频和图片生成你的数字人口播

带表情、带头部运动。适合做一些名人短视频鸡汤口播 类似此前微软和阿里emo那个方案 1、介绍: 能够通过单张静态肖像和输入音频生成具有自然流动运动的谈话视频,它采用了一种普遍的运动表示方法,能够捕捉广泛的面部动态,包括细微的表情和头部运动。 2、框架概述 (1)该…

【18-Ⅰ】Head First Java 学习笔记

HeadFirst Java 本人有C语言基础&#xff0c;通过阅读Java廖雪峰网站&#xff0c;简单速成了java&#xff0c;但对其中一些入门概念有所疏漏&#xff0c;阅读本书以弥补。 第一章 Java入门 第二章 面向对象 第三章 变量 第四章 方法操作实例变量 第五章 程序实战 第六章 Java…

信息检索(37):Query-as-context Pre-training for Dense Passage Retrieval

Query-as-context Pre-training for Dense Passage Retrieval 标题摘要1 引言2 初步&#xff1a;上下文监督预训练2.1 coCondenser2.2 CoT-MAE 3 查询即上下文预训练3.1 预训练3.2 微调 4 实验4.1 预训练4.2 微调4.3 基线4.4 主要结果4.5 域外评估 5 分析5.1 生成的查询数量的影…

【QuikGraph】C#调用第三方库实现迪杰斯特拉(Dijkstra)算法功能

QuikGraph库介绍 项目地址&#xff1a;https://github.com/KeRNeLith/QuikGraph QuikGraph为.NET提供了通用的有向/无向图数据结构和算法。 QuikGraph提供了深度优先搜索、广度优先搜索、A*搜索、最短路径、k最短路径&#xff0c;最大流量、最小生成树等算法。 QuikGraph最初…