前端原生写自定义旋转变换轮播图

html部分:

 

<div class="banner_box">
    <div class="swiperWrapper" v-show="bannerList.length>0">
         <div class="swiper-item" :id="`swiperSlide${index}`" :class="{'active':index==0,'next':index==1,'prev':index==2}" @click="swiperChange(item,index)" v-for="(item,index) in bannerList" :key="index">
             <img class="bus_img" style="width:100%;height:auto;max-width: 1200px;" :src="item.img_url">
			 <div class="txt_box txtBox" :class="{'txtBox_active':item.active}" >
                 <p class="f_t_16 desc" v-html="item.desc"></p>
                 <p class="f_t_20 title">{{ item.title }}</p>
             </div>
          </div>
          <div class="dot">
              <i class="el-icon-arrow-left icon-prev" @click="swiperButtonChange('prev')"></i>
              <div v-for="(item,index) in bannerList" :key="index" :class="{'active':item.active}" @click="swiperChange(item,index)"></div>
              <i class="el-icon-arrow-right icon-next" @click="swiperButtonChange('next')"></i>
           </div>
     </div>
</div>

css部分:

/* 自定义轮播图样式 */
.banner_box{    
    width: 1100px;
    height: 856px;
    margin: 100px auto -70px auto;
    position: relative;
    box-sizing: border-box;
}
.swiper-item{
    transition: bottom 1s ease-in-out,left 1s ease-in-out,width 1s ease-in-out,height 1s ease-in-out,z-index 0s linear 1s;
    cursor: pointer;
    position: absolute;
}
.swiperWrapper{
    height: 100%;
}
.swiperWrapper .active{
    bottom: 380px;
    left: 215px;
    z-index: 10;
    width: 883px;
    height: 464px;
}
.swiperWrapper .next{
    bottom: 170px;
    left: 7%;
    z-index: 20;
    width: 386px;
    height: 257px;
}
.swiperWrapper .prev{
    bottom: 360px;
    left: 0%;
    z-index: 30;
    width: 194px;
    height: 130px;
}
.txtBox{
    bottom: 9%;
    line-height: unset;
    width: 36.9%;
    background-color: #FFFFFF;
    position: absolute;
    right: 5%;
    padding: 20px 24px;
    box-sizing: border-box;
    font-size: 24px;
    color: #004388;
    text-align: left;
}
.txtBox{
    opacity: 0;
    visibility: hidden;
    right: 30px;
    bottom: -90px;
    width: 575px;
}
.txtBox_active{
    visibility: visible;
    opacity: 1;
    transition: all .6s ease-in-out 1s;
}
.txtBox .title{
    font-size: 20px;
    font-family: theSans;
    font-weight: 500;
    color: #333333;
 }
.txtBox .desc{
    font-size: 16px;
    font-family: SourceHanSansSC-Medium, SourceHanSansSC;
    font-weight: 500;
    color: #004388;
    margin-bottom: 39px;
 }
.newPointer{
    transform: translate(160px,315px);
}
.dot{
    width: 120px;
    height: 20px;
    position: absolute;
    left: 44%;
    bottom: 220px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.dot>div{
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #004387;
    transition: background-color 0.3s ease-in-out;
    cursor: pointer;
}
.dot>div:hover{
    background-color: #02A6E3;
    transition: background-color 0.3s ease-in-out;
}
.dot .active{
    width: 10px;
    height: 10px;
    background-color: #02A6E3;
    transition: background-color 0.3s ease-in-out;
}

.dot .icon-prev,.dot .icon-next{
    font-weight: bold;
    color: #02A6E3;
    font-size: 18px;
    cursor: pointer;
}

js部分:

data定义bannerList:

// 轮播图列表
bannerList: []

获取轮播图数据:

this.bannerList = res.data.chart;
this.bannerList.forEach((item,index)=>{
    item.active = index == 0;
});

轮播图方法:

/**
 * 轮播图点击
 */
swiperChange(item,index){
   let activeIndex = this.bannerList.findIndex(item => item.active == true);
   // 如果选中的是当前active的无效果
   if (index == activeIndex) return false;
   let swiper0 = document.getElementById(`swiperSlide0`); 
   let swiper1 = document.getElementById(`swiperSlide1`); 
   let swiper2 = document.getElementById(`swiperSlide2`); 
   let swiper = document.getElementById(`swiperSlide${index}`);
   let classList = [...swiper.classList];
   this.bannerList.map(item=>{
       return item.active = false;
   });

   if (index == 0 && classList.includes('next')) {
       swiper0.classList.remove('next');
       swiper0.classList.add('active');
                
       swiper1.classList.remove('prev');
       swiper1.classList.add('next');
                
       swiper2.classList.remove('active');
       swiper2.classList.add('prev');

       this.bannerList[0].active = true;
       this.$set(this.bannerList,0,{ ...this.bannerList[0], active: true });
       this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
       this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
   } else if (index == 0 && classList.includes('prev')) {
       swiper0.classList.remove('prev');
       swiper0.classList.add('active');
                
       swiper1.classList.remove('active');
       swiper1.classList.add('next');
                
       swiper2.classList.remove('next');
       swiper2.classList.add('prev');

       this.bannerList[0].active = true;
       this.$set(this.bannerList,0,{ ...this.bannerList[0], active: true });
       this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
       this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
   } else if (index == 1 && classList.includes('next')) {
       swiper0.classList.remove('active');
       swiper0.classList.add('prev');
                
       swiper1.classList.remove('next');
       swiper1.classList.add('active');
                
       swiper2.classList.remove('prev');
       swiper2.classList.add('next');
                    
       this.bannerList[1].active = true;
       this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
       this.$set(this.bannerList,1,{ ...this.bannerList[1], active: true });
       this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
   } else if (index == 1 && classList.includes('prev')) {
       swiper0.classList.remove('next');
       swiper0.classList.add('prev');
                
       swiper1.classList.remove('prev');
       swiper1.classList.add('active');
                
       swiper2.classList.remove('active');
       swiper2.classList.add('next');
                
       this.bannerList[1].active = true;
       this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
       this.$set(this.bannerList,1,{ ...this.bannerList[1], active: true });
       this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
   } else if (index == 2 && classList.includes('next')) {
       swiper0.classList.remove('prev');
       swiper0.classList.add('next');
                
       swiper1.classList.remove('active');
       swiper1.classList.add('prev');
                
       swiper2.classList.remove('next');
       swiper2.classList.add('active');
                
       this.bannerList[2].active = true;
       this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
       this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
       this.$set(this.bannerList,2,{ ...this.bannerList[2], active: true });
   } else if (index == 2 && classList.includes('prev')) {
       swiper0.classList.remove('active');
       swiper0.classList.add('next');
                
       swiper1.classList.remove('next');
       swiper1.classList.add('prev');
                    
       swiper2.classList.remove('prev');
       swiper2.classList.add('active');
                
       this.bannerList[2].active = true;
       this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
       this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
       this.$set(this.bannerList,2,{ ...this.bannerList[2], active: true });
   }
},
/**
 * 前进和后退点击
 */
swiperButtonChange(type){
   let swiper0 = document.getElementById(`swiperSlide0`); 
   let swiper1 = document.getElementById(`swiperSlide1`); 
   let swiper2 = document.getElementById(`swiperSlide2`); 
   let classList = [...swiper0.classList];
   this.bannerList.map(item=>{
       return item.active = false;
   });
   // 以第一张图片为基准判断
   if (type == 'prev') {
      if (classList.includes('active')) {
         swiper0.classList.remove('active');
         swiper0.classList.add('next');
                    
         swiper1.classList.remove('next');
         swiper1.classList.add('prev');
                    
         swiper2.classList.remove('prev');
         swiper2.classList.add('active');
                
         this.bannerList[2].active = true;
         this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
         this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
         this.$set(this.bannerList,2,{ ...this.bannerList[2], active: true });
      } else if (classList.includes('next')) {
         swiper0.classList.remove('next');
         swiper0.classList.add('prev');
                        
         swiper1.classList.remove('prev');
         swiper1.classList.add('active');
                    
         swiper2.classList.remove('active');
         swiper2.classList.add('next');
                
         this.bannerList[1].active = true;
         this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
         this.$set(this.bannerList,1,{ ...this.bannerList[1], active: true });
         this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
      } else if (classList.includes('prev')) {
         swiper0.classList.remove('prev');
         swiper0.classList.add('active');
                        
         swiper1.classList.remove('active');
         swiper1.classList.add('next');
                            
         swiper2.classList.remove('next');
         swiper2.classList.add('prev');
                
         this.bannerList[0].active = true;
         this.$set(this.bannerList,0,{ ...this.bannerList[0], active: true });
         this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
         this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
      }
   } else if (type == 'next') {
      if (classList.includes('active')) {
         swiper0.classList.remove('active');
         swiper0.classList.add('prev');
                    
         swiper1.classList.remove('next');
         swiper1.classList.add('active');
                    
         swiper2.classList.remove('prev');
         swiper2.classList.add('next');
                
         this.bannerList[1].active = true;
         this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
         this.$set(this.bannerList,1,{ ...this.bannerList[1], active: true });
         this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
      } else if (classList.includes('next')) {
         swiper0.classList.remove('next');
         swiper0.classList.add('active');
                    
         swiper1.classList.remove('prev');
         swiper1.classList.add('next');
                    
         swiper2.classList.remove('active');
         swiper2.classList.add('prev');
                
         this.bannerList[0].active = true;
         this.$set(this.bannerList,0,{ ...this.bannerList[0], active: true });
         this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
         this.$set(this.bannerList,2,{ ...this.bannerList[2], active: false });
      } else if (classList.includes('prev')) {
         swiper0.classList.remove('prev');
         swiper0.classList.add('next');
                    
         swiper1.classList.remove('active');
         swiper1.classList.add('prev');
                    
         swiper2.classList.remove('next');
         swiper2.classList.add('active');
                
         this.bannerList[2].active = true;
         this.$set(this.bannerList,0,{ ...this.bannerList[0], active: false });
         this.$set(this.bannerList,1,{ ...this.bannerList[1], active: false });
         this.$set(this.bannerList,2,{ ...this.bannerList[2], active: true });
       }
   }
}

 轮播图数据结构:

[
    {
        "id": 44,
        "title": "李刚,班组长",
        "img_url": "http://cdn.juplus.cn/FhR4NNaOEHIsn2Uz-KePR3I1A4No",
        "desc": "“在科德宝工作意味着拥有自由并设定可持续发展足迹。”",
        "subtitle": null,
        "video_url": null,
        "subtitle1": null,
        "type": 3,
        "create_time": "2023-08-11 09:14:59",
        "sort": 1,
        "active": true
    },
    {
        "id": 43,
        "title": "利里奥(Lirio),销售主管",
        "img_url": "http://cdn.juplus.cn/FhLtUKcYxOLwQrabkylp5jV2RGap",
        "desc": "“我为在这里工作感到自豪,因为我在职业生涯中有很多发展机会。”",
        "subtitle": null,
        "video_url": null,
        "subtitle1": null,
        "type": 3,
        "create_time": "2023-08-11 09:14:20",
        "sort": 2,
        "active": false
    },
    {
        "id": 56,
        "title": "达伦(Darren),销售主管",
        "img_url": "http://cdn.juplus.cn/Fls4sM6DPjgV0gxbHc59torADFZD",
        "desc": "“科德宝一直求才若渴,我们理想的人才求知欲强,积极主动,希望获得成长和发展个人技能。”",
        "subtitle": null,
        "video_url": null,
        "subtitle1": null,
        "type": 3,
        "create_time": "2023-08-17 13:31:55",
        "sort": 3,
        "active": false
    }
]

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

深度学习实战基础案例——卷积神经网络(CNN)基于SqueezeNet的眼疾识别|第1例

文章目录 前言一、数据准备1.1 数据集介绍1.2 数据集文件结构 二、项目实战2.1 数据标签划分2.2 数据预处理2.3 构建模型2.4 开始训练2.5 结果可视化 三、数据集个体预测 前言 SqueezeNet是一种轻量且高效的CNN模型&#xff0c;它参数比AlexNet少50倍&#xff0c;但模型性能&a…

Springboot写单元测试

导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintag…

Python学习笔记_基础篇(七)_常用模块

模块&#xff0c;用一砣代码实现了某个功能的代码集合。 类似于函数式编程和面向过程编程&#xff0c;函数式编程则完成一个功能&#xff0c;其他代码用来调用即可&#xff0c;提供了代码的重用性和代码间的耦合。而对于一个复杂的功能来&#xff0c;可能需要多个函数才能完成…

机器人CPP编程基础-03变量类型Variables Types

机器人CPP编程基础-02变量Variables 全文AI生成。 C #include<iostream>using namespace std;main() {int a10,b35; // 4 bytescout<<"Value of a : "<<a<<" Address of a : "<<&a <<endl;cout<<"Val…

详细记录Pycharm配置已安装好的Conda虚拟环境

当安装好conda环境之后&#xff0c;想要在Pycharm中使用&#xff0c;那么就要在Pycharm中导入&#xff0c;我这里使用的pycharm-professional-2023.2这个版本&#xff0c;下面是详细步骤&#xff1a; 1.打开File->Settings&#xff1a; 2.找到Project——>Python Inter…

网络层协议

网络层协议 IP协议基本概念协议头格式网段划分特殊的IP地址IP地址的数量限制私有IP地址和公网IP地址路由IP协议头格式后续 在复杂的网络环境中确定一个合适的路径 IP协议 承接上文&#xff0c;TCP协议并不会直接将数据传递给对方&#xff0c;而是交付给下一层协议&#xff0c;…

LeetCode Top100 Liked 题单(序号34~51)

​34. Find First and Last Position of Element in Sorted Array ​ 题意&#xff1a;找到非递减序列中目标的开头和结尾 我的思路 用二分法把每一个数字都找到&#xff0c;最后返回首尾两个数 代码 Runtime12 ms Beats 33.23% Memory14 MB Beats 5.16% class Solution {…

ssh远程连接服务器

一、远程连接服务器简介 二、连接加密技术简介 三、ssh服务配置 四、用户登录ssh服务 Enforcing会强制限制&#xff0c;如端口为22&#xff0c;可以访问&#xff0c;如果是2000端口&#xff0c;不能使用 Permissive是宽容的模式&#xff0c;不限制使用端口 Enforcing会重启失败…

Redis系列(一):深入了解Redis数据类型和底层数据结构

Redis有以下几种常用的数据类型&#xff1a; redis数据是如何组织的 为了实现从键到值的快速访问&#xff0c;Redis 使用了一个哈希表来保存所有键值对。 Redis全局哈希表&#xff08;Global Hash Table&#xff09;是指在Redis数据库内部用于存储所有键值对的主要数据结构。…

(三)行为模式:2、命令模式(Command Pattern)(C++示例)

目录 1、命令模式&#xff08;Command Pattern&#xff09;含义 2、命令模式的UML图学习 3、命令模式的应用场景 4、命令模式的优缺点 5、C实现命令模式的实例 1、命令模式&#xff08;Command Pattern&#xff09;含义 命令模式&#xff08;Command&#xff09;&#xff…

亚马逊、ebay、虾皮电商卖家如何做测评,提高店铺排名?

测评是什么呢&#xff1f; 不管是在亚马逊&#xff0c;速卖通&#xff0c;阿里国际&#xff0c;虾皮&#xff0c;Lazada&#xff0c;沃尔玛&#xff0c;美客多&#xff0c;ebay等跨境电商平台&#xff0c;测评都是成本最低且最有效的一种推广方式。 通俗来说&#xff0c;测评…

leetcode292. Nim 游戏(博弈论 - java)

Nim 游戏 Nim 游戏题目描述博弈论 上期经典算法 Nim 游戏 难度 - 简单 原题链接 - Nim游戏 题目描述 你和你的朋友&#xff0c;两个人一起玩 Nim 游戏&#xff1a; 桌子上有一堆石头。 你们轮流进行自己的回合&#xff0c; 你作为先手 。 每一回合&#xff0c;轮到的人拿掉 1 -…

MySQL 中 不等于 会过滤掉 Null 的问题

null值与任意值比较时都为fasle not in 、"!"、"not like"条件过滤都会过滤掉null值的数据 SELECT * from temp; SELECT * from temp where score not in (70); 返回null解决方法: SELECT * from temp where score not in (70) or score is null;SELECT…

OC调用Swift编写的framework

一、前言 随着swift趋向稳定&#xff0c;越来越多的公司都开始用swift来编写苹果相关的业务了&#xff0c;关于swift的利弊这里就不多说了。这里详细介绍OC调用swift编写的framework库的步骤 二、制作framework 1、新建项目&#xff0c;选择framework 2、填写framework的名称…

Excel革命,基于电子表格开发的新工具,不是Access和Power Fx

深谙其道 在日常工作中&#xff0c;Excel是许多人不可或缺的办公工具。 是微软的旗下产品&#xff0c;属于Microsoft 365套件中的一部分&#xff0c;强大的数据处理和计算功能&#xff0c;被普遍应用在全球各行各业的人群当中&#xff0c;是一款强大且普及的电子表格软件。 于…

Salient主题 - 创意多用途和WooCommerce商城主题

Salient主题是下一代WordPress主题&#xff0c;给任何人带来专业的设计结果&#xff0c;而不需要任何编码。Salient 提供永久更新的专业剖面模板库&#xff0c;目前有超过425个可供选择 – 所有这些都充满热情并坚持高标准的审美质量。 网址: Salient主题 - 创意多用途和WooCo…

Google play应用成功上架要点——如何防止封号、拒审、下架?

Google Play是全球最大的移动应用商店之一&#xff0c;它是运行Android操作系统的设备的官方应用商店。它提供各种数字内容&#xff0c;包括应用程序&#xff08;应用&#xff09;、游戏、音乐、书籍等&#xff0c;包括免费和付费选项。这也为许多游戏/APP出海的企业或开发者提…

Vue CLI创建Vue项目详细步骤

&#x1f680; 一、安装Node环境&#xff08;建议使用LTS版本&#xff09; 在开始之前&#xff0c;请确保您已经安装了Node.js环境。您可以从Node.js官方网站下载LTS版本&#xff0c;以确保稳定性和兼容性。 中文官网下载 确认已安装 Node.js。可以在终端中运行 node -v 命令…

【AI大模型】训练Al大模型 (上篇)

大模型超越AI 前言 洁洁的个人主页 我就问你有没有发挥&#xff01; 知行合一&#xff0c;志存高远。 目前所指的大模型&#xff0c;是“大规模深度学习模型”的简称&#xff0c;指具有大量参数和复杂结构的机器学习模型&#xff0c;可以处理大规模的数据和复杂的问题&#x…

缓存平均的两种算法

引言 线边库存物料的合理性问题是物流仿真中研究的重要问题之一,如果线边库存量过多,则会对生产现场的布局产生负面影响,增加成本,降低效益。 写在前面 仿真分析后对线边Buffer的使用情况进行合理的评估就是一个非常重要的事情。比较关心的参数包括:缓存位最大值…