Swiper实现轮播效果

swiper官网:https://3.swiper.com.cn/

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://unpkg.com/swiper@8/swiper-bundle.min.css"
    />
    <script src="https://unpkg.com/swiper@8/swiper-bundle.min.js"></script>
  </head>
  <style>
    .swiper {
      width: 620px;
      height: 720px;
    }

    /* 左右箭头 */
    .swiper-button-prev:after {
      display: none;
    }
    .swiper-button-prev {
      background: url("./image/left-1.png");
      background-size: contain;
      background-repeat: no-repeat;
      width: 110px;
      height: 120px;
      left: 5px;
    }
    .swiper-button-next:after {
      display: none;
    }
    .swiper-button-next {
      background: url("./image/right-1.png");
      background-size: contain;
      background-repeat: no-repeat;
      width: 110px;
      height: 120px;
      right: 0px;
      z-index: 999;
      position: absolute;
    }

    /* 图片显示 */
    .swiper-slide {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .swiper-slide img {
      width: 300px;
    }
    .swiper-slide-active img {
      position: absolute;
      width: 395px;
      transition: width 0.5s;
    }
    .swiper-slide-next img {
      position: absolute;
      left: -230px;
    }
    .swiper-slide-prev img {
      position: absolute;
      right: -230px;
    }
    .swiper-slide-active {
      z-index: 999;
    }
    .swiper-slide-next {
      z-index: 888;
    }
    .swiper-slide-prev {
      z-index: 888;
    }
    .bullet-style {
      width: 0px;
      height: 0px;
      border: 6px solid black;
      background-color: black;
      background-clip: padding-box;
      transform: rotateZ(45deg);
      display: inline-block;
      margin: 0 8px;
      cursor: pointer;
    }
    .bullet-style:hover {
      border-color: gray;
      background-color: gray;
    }
    .bullet-style-active {
      border-style: double;
      border-width: 8px;
    }
  </style>
  <body>
    <div class="swiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <img src="./image/world-3-3-1.png" />
        </div>
        <div class="swiper-slide">
          <img src="./image/world-4-4-1.png" />
        </div>
        <div class="swiper-slide">
          <img src="./image/world-2-2-1.png" />
        </div>
      </div>
      <!-- 分页器 -->
      <div class="swiper-pagination"></div>

      <!--前进后退按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>
    <!-- <div class="swiper-button-next swiper-button-black"></div> -->
    <script type="module">
      import Swiper from "https://unpkg.com/swiper@8/swiper-bundle.esm.browser.min.js";
      let addBullentsEvent = () => {};
      const mySwiper = new Swiper(".swiper", {
        loop: true, // 循环模式选项
        // 分页器
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
          // 自定义分页其样式
          type: "custom",
          renderCustom: function (swiper, current, total) {
            let renderHTML = "";
            for (let i = 0; i < total; i++) {
              if (i + 1 == current) {
                renderHTML += `<div class="bullet-style bullet-style-active"></div>`;
              } else {
                renderHTML += `<div class="bullet-style"></div>`;
              }
            }
            return renderHTML;
          },
        },
        // 前进后退按钮
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },

        slidesPerView: 2, //设置slider容器能够同时显示的slides数量
        spaceBetween: 80, //slide之间的距离(单位px)
        centeredSlides: true, //设定为true时,active slide会居中,而不是默认状态下的居左。
        observer: true, //修改swiper自己或子元素时,重新加载
        observeParents: true, //修改swiper的父元素时,重新加载
        centerInsufficientSlides: true, //当slides 的总数小于 slidesPerView 时,slides居中。
        autoplay: {
          delay: 3000, //3秒切换一次
        },

        // 事件

        on: {
          paginationRender: function () {
            console.log("分页器渲染了");
            // 重新添加事件
            addBullentsEvent();
          },
          autoplayStart: function () {
            console.log("开始自定切换");
          },
          autoplayStop: function () {
            console.log("关闭自动切换");
          },
        },
      });

      addBullentsEvent = () => {
        const bullents = document.getElementsByClassName("bullet-style");
        for (let i = 0; i < bullents.length; i++) {
          console.log("obj.onclick", bullents[i].onclick);
          bullents[i].removeEventListener("click", () => {});
          bullents[i].addEventListener("click", function () {
            mySwiper.slideTo(i + 2); //切换到对应的slide,速度为1秒
            mySwiper.autoplay.start();
          });
        }
      };

      window.addEventListener("load", () => {
        addBullentsEvent();
        document
          .getElementsByClassName("swiper-button-next")[0]
          .addEventListener("click", () => {
            mySwiper.autoplay.start();
          });
        document
          .getElementsByClassName("swiper-button-prev")[0]
          .addEventListener("click", () => {
            mySwiper.autoplay.start();
          });
      });
    </script>
  </body>
</html>

效果:
在这里插入图片描述

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

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

相关文章

苹果的“汽车梦”宣告失败,转战AI?能hold住吗?

文 | BFT机器人 一觉睡醒&#xff0c;苹果就宣布了一件爆炸性的新闻&#xff0c;那就是坚持多年和受到很多行业大佬支持和期待的“泰坦”宣布结束了&#xff01;将原有负责汽车项目的大部分主力军转战到AI核心上&#xff0c;这消息一出&#xff0c;业内外纷纷对苹果的这个决定…

仓储自动化新解:托盘四向穿梭车驶入智能工厂 智能仓储与产线紧密结合

目前&#xff0c;由于对仓库存储量的要求越来越高&#xff0c;拣选、输送以及出入库频率等要求也越来越高&#xff0c;对此&#xff0c;在物流仓储领域&#xff0c;自动化与智能化控制技术得以快速发展&#xff0c;货架穿梭车在自动库领域的应用越来越广泛。现阶段&#xff0c;…

从 iOS 设备恢复数据的 20 个iOS 数据恢复工具

作为 iPhone、iPad 或 iPod 用户&#xff0c;您可能普遍担心自己可能会丢失存储在珍贵 iOS 设备中的所有宝贵数据。数据丢失的原因多种多样&#xff0c;这里列出了一些常见原因&#xff1a; 1. iOS 软件更新 2. 恢复出厂设置 3. 越狱 4. 误操作删除数据 5. iOS 设备崩溃 …

CMake、OpenCV 和单元测试

我写了很多关于 CMake 的文章&#xff0c;如果你感兴趣&#xff0c;可以点击以下链接阅读&#xff1a; CMake VS MakeCMake&#xff1a;在构建世界掀起风暴现代 CMake 使用技巧CMake 交叉编译CMake 生成器已开启 我们将继续对 CMake 的探索&#xff0c;这篇文章技术性高&…

如何解决 C/C++ 编译器优化导致的编译BUG(程序崩溃)支援VC++/CLANG/GCC

本文仅适用于&#xff0c;有愿意、爱捣鼓的童靴。 因编译器优化导致编译BUG&#xff0c;即DEBUG下面无故障稳定工作&#xff0c;但RELESE下程序会在特定函数位置上崩溃。 这要求 C/C 开发人员拥有最基本的素质&#xff0c;需要能够承受&#xff0c;逐行审视编译器输出的目标平…

获取当前数据 上下移动

点击按钮 上下移动 当前数据 代码 // 出国境管理 登记备案人员列表 <template><a-row><a-col span"24"><a-card :class"style[a-table-wrapper]"><!-- 出国境 登记备案人员列表 --><a-table:rowKey"records >…

【Java】查看class文件的jdk编译版本的两种方式

一、使用文本编辑工具EditPlus 使用EditPlus打开该class文件&#xff0c;字符集选择16进制&#xff08;Hex viewer&#xff09;。 仅看第一行数据&#xff0c;前面8个字节CA FE BA BE是固定的。 之后4个字节00 00 是次版本。 次版本后面的4个字节00 34 就是jdk版本。 jdk版本…

Java代码块

Java代码块 普通代码块 普通代码块在对象创建时执行&#xff0c;创建一个对象就会执行一次&#xff0c;可把构造函数中的冗余代码放到普通代码块中 public class Test {public void method() {// 普通代码块{int x 10;System.out.println(x);}public method(){}} }普通代码块…

使用mininet快速入门ONOS路由交换技术与原理-路由篇

上篇文章 《使用mininet快速入门ONOS路由交换技术与原理-交换篇》 使用mininet搭建了一个简单的网络拓扑&#xff0c;并实现了同一交换机下同网段多主机的通信&#xff0c;其中涉及到的通信知识主要以二层mac地址通信为主。 但在芸芸网络的世界中&#xff0c;主机间的通信除了…

Education Codeforces Round 162(Div.2) A~E

A.Moving Chips (思维) 题意&#xff1a; 给一个长度为 n n n的数组 a a a&#xff0c; a i 1 a_i1 ai​1或者 a i 0 a_i0 ai​0&#xff0c;现在可以选择一个 1 1 1&#xff0c;然后将其与左侧最近的 0 0 0交换。询问使得所有的 1 1 1连在一起&#xff0c;中间没有 0 0 0…

Vue+SpringBoot打造不良邮件过滤系统

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 系统用户模块2.2 收件箱模块2.3 发件箱模块2.4 垃圾箱模块2.5 回收站模块2.6 邮箱过滤设置模块 三、实体类设计3.1 系统用户3.2 邮件3.3 其他实体 四、系统展示五、核心代码5.1 查询收件箱档案5.2 查询回收站档案5.3 新…

js 面试 1判断变量是否是数组 2 检测数据类型方法

1 是否是数组 1) typeof 检测数据类型运算符 优点&#xff1a;使用简单 缺点&#xff1a;只能检测基本类型&#xff08;除null外&#xff09; console.log(typeof(10)) //Number console.log(typeof(false)) //boolean console.log(typeof(hello)) //string console.log(typeof…

LeetCode 刷题 [C++] 第236题.二叉树的最近公共祖先

题目描述 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为&#xff1a;“对于有根树 T 的两个节点 p、q&#xff0c;最近公共祖先表示为一个节点 x&#xff0c;满足 x 是 p、q 的祖先且 x 的深度尽可能大&#xff08;一个节点也可以…

【网络编程】理解客户端和服务器并使用Java提供的api实现回显服务器

目录 一、网络编程 二、客户端和服务器 三、客户端和服务器的交互模式 四、TCP 和 UDP UDP socket api 的使用 1、DatagramSoket 2、DatagramPacket TCP socket api 的使用 1、ServerSocket 2、Socket 一、网络编程 本质上就是学习传输层给应用层提供的 api&#x…

MySQL之事务详解

华子目录 什么是事务银行转账案例方式1方式2具体操作 事务的四大特性并发事务问题脏读不可重复读幻读 事务的隔离级别查看事务隔离级别设置事务隔离级别 session与global的区别 什么是事务 事务&#xff08;transaction&#xff09;&#xff0c;一个最小的不可再分的工作单元&…

实例:NX二次开发抽取平面以及标准柱面中心线

一、概述 最近体验许多外挂&#xff0c;包括胡波外挂、星空外挂及模圣等都有抽取面的中心线&#xff0c;由于刚刚学习&#xff0c;我尝试看看能不能做出来&#xff0c;本博客代码没有封装函数&#xff0c;代码有待改进&#xff0c;但基本可以实现相应的功能。 二、案例实现的功…

Sora 原理与技术实战笔记一

b 站视频合集 【AIX组队学习】Sora原理与技术实战&#xff1a;Sora技术路径详解 Sora 技术报告&#xff08;OpenAI&#xff09; huggingsd 文生图视频系列的一个开源项目 最强视频生成模型Sora相关技术解析 https://github.com/lichao-sun/SoraReview 惊艳效果&#xff1a; 长…

Ps:路径面板

Ps菜单&#xff1a;窗口/路径 Window/Paths “路径”面板 Paths Panel提供了一系列功能&#xff0c;使用户能够创建、编辑、保存和利用路径。 ◆ ◆ ◆ 路径分类 在“路径”面板上的路径可分为五大类。 常规路径 Saved Path 也称“已保存的路径”&#xff0c;指的是已经存储在…

Python进阶学习:Pandas--DataFrame--如何把几列数据合并成新的一列

Python进阶学习&#xff1a;Pandas–DataFrame–如何把几列数据合并成新的一列 &#x1f308; 个人主页&#xff1a;高斯小哥 &#x1f525; 高质量专栏&#xff1a;Matplotlib之旅&#xff1a;零基础精通数据可视化、Python基础【高质量合集】、PyTorch零基础入门教程&#x1…

SpringMVC的配置2种(本质上还是一样的,实现的接口不同)

第一种SpringInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer 看第一种配置 package com.xxx.config; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; public class SpringInitConfig ext…
最新文章