• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Swiper插件的安装和使用

武飞扬头像
我会做水煮肉
帮助5

一、Swiper简介

swiper是一款轻量级的轮播图插件,开源、免费、稳定、使用简单且功能强大,由纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端,能实现触屏焦点图、触屏Tab切换、触屏轮播图切换等常用效果,是架构移动终端网站的重要选择!

二、安装方法

  1. 如图点击下载Swiper;学新通
  2. 如图点击下载压缩文件夹,也可点击下方下载地址进行下载;swiper-4.5.3.zip学新通https://www.swiper.com.cn/download/swiper-4.5.3.zip学新通
  3. 如图点击文件夹中的dist文件夹,找到css文件夹中的swiper.css文件和js文件夹中的swiper.js文件,并将这两个文件复制到自己的项目中;学新通学新通学新通
  4. Swiper中文网链接地址Swiper中文网-轮播图幻灯片js插件,H5页面前端开发学新通https://www.swiper.com.cn/

三、使用方法

  1. 引入文件
    1.  
      <link rel="stylesheet" href="css/swiper.css" />
    2.  
      <script src="js/swiper.js"></script>
  2. HTML部分
    1.  
      <div class="swiper">
    2.  
      <div class="swiper-container">
    3.  
      <div class="swiper-wrapper">
    4.  
      <div class="swiper-slide">
    5.  
      <img src="img/1.png" alt="">
    6.  
      </div>
    7.  
      <div class="swiper-slide">
    8.  
      <img src="img/2.png" alt="">
    9.  
      </div>
    10.  
      <div class="swiper-slide">
    11.  
      <img src="img/3.png" alt="">
    12.  
      </div>
    13.  
      </div>
    14.  
      <!-- 分页器 -->
    15.  
      <div class="swiper-pagination"></div>
    16.  
       
    17.  
      <!-- 导航按钮 -->
    18.  
      <div class="swiper-button-prev">
    19.  
      <svg t="1669042346665" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
    20.  
      p-id="4658" width="200" height="200">
    21.  
      <path
    22.  
      d="M452.266667 507.733333l-29.866667 29.866667 29.866667 29.866667 115.2 115.2 29.866666-29.866667-115.2-115.2L597.333333 422.4l-29.866666-29.866667-115.2 115.2z m81.066666 388.266667c200.533333 0 362.666667-162.133333 362.666667-362.666667S733.866667 170.666667 533.333333 170.666667 170.666667 332.8 170.666667 533.333333 332.8 896 533.333333 896z m0-42.666667C358.4 853.333333 213.333333 708.266667 213.333333 533.333333S358.4 213.333333 533.333333 213.333333 853.333333 358.4 853.333333 533.333333 708.266667 853.333333 533.333333 853.333333z"
    23.  
      fill="#444444" p-id="4659"></path>
    24.  
      </svg>
    25.  
      </div>
    26.  
      <div class="swiper-button-next">
    27.  
      <svg t="1669042362801" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
    28.  
      p-id="5570" width="200" height="200">
    29.  
      <path
    30.  
      d="M614.4 507.733333l29.866667 29.866667-29.866667 29.866667-115.2 115.2-29.866667-34.133334 115.2-115.2L469.333333 422.4l29.866667-29.866667 115.2 115.2zM533.333333 896C332.8 896 170.666667 733.866667 170.666667 533.333333S332.8 170.666667 533.333333 170.666667 896 332.8 896 533.333333 733.866667 896 533.333333 896z m0-42.666667c174.933333 0 320-145.066667 320-320S708.266667 213.333333 533.333333 213.333333 213.333333 358.4 213.333333 533.333333 358.4 853.333333 533.333333 853.333333z"
    31.  
      fill="#444444" p-id="5571"></path>
    32.  
      </svg>
    33.  
      </div>
    34.  
       
    35.  
      <!-- 滚动条 -->
    36.  
      <!-- <div class="swiper-scrollbar"></div> -->
    37.  
      </div>
    学新通
  3. JS部分
    1.  
      <script>
    2.  
      var mySwiper1 = new Swiper(".swiper-container", {
    3.  
      navigation: {
    4.  
      nextEl: ".swiper-button-next",
    5.  
      prevEl: ".swiper-button-prev",
    6.  
      },
    7.  
      loop: true,
    8.  
      autoplay: true,
    9.  
      keyboard: true,
    10.  
      zoom: true,
    11.  
      pagination: {
    12.  
      el: '.swiper-pagination',
    13.  
      dynamicBullets: true,
    14.  
      },
    15.  
      });
    16.  
      </script>
    学新通
  4. 整体代码
    1.  
      <!DOCTYPE html>
    2.  
      <html>
    3.  
      <head>
    4.  
      <meta charset="utf-8" />
    5.  
      <title></title>
    6.  
      <link rel="stylesheet" href="css/swiper.css" />
    7.  
      <script src="js/swiper.js"></script>
    8.  
      </head>
    9.  
      <body>
    10.  
      <div class="swiper">
    11.  
      <div class="swiper-container">
    12.  
      <div class="swiper-wrapper">
    13.  
      <div class="swiper-slide">
    14.  
      <img src="img/1.png" alt="">
    15.  
      </div>
    16.  
      <div class="swiper-slide">
    17.  
      <img src="img/2.png" alt="">
    18.  
      </div>
    19.  
      <div class="swiper-slide">
    20.  
      <img src="img/3.png" alt="">
    21.  
      </div>
    22.  
      </div>
    23.  
      <!-- 分页器 -->
    24.  
      <div class="swiper-pagination"></div>
    25.  
       
    26.  
      <!-- 导航按钮 -->
    27.  
      <div class="swiper-button-prev">
    28.  
      <svg t="1669042346665" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
    29.  
      p-id="4658" width="200" height="200">
    30.  
      <path
    31.  
      d="M452.266667 507.733333l-29.866667 29.866667 29.866667 29.866667 115.2 115.2 29.866666-29.866667-115.2-115.2L597.333333 422.4l-29.866666-29.866667-115.2 115.2z m81.066666 388.266667c200.533333 0 362.666667-162.133333 362.666667-362.666667S733.866667 170.666667 533.333333 170.666667 170.666667 332.8 170.666667 533.333333 332.8 896 533.333333 896z m0-42.666667C358.4 853.333333 213.333333 708.266667 213.333333 533.333333S358.4 213.333333 533.333333 213.333333 853.333333 358.4 853.333333 533.333333 708.266667 853.333333 533.333333 853.333333z"
    32.  
      fill="#444444" p-id="4659"></path>
    33.  
      </svg>
    34.  
      </div>
    35.  
      <div class="swiper-button-next">
    36.  
      <svg t="1669042362801" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
    37.  
      p-id="5570" width="200" height="200">
    38.  
      <path
    39.  
      d="M614.4 507.733333l29.866667 29.866667-29.866667 29.866667-115.2 115.2-29.866667-34.133334 115.2-115.2L469.333333 422.4l29.866667-29.866667 115.2 115.2zM533.333333 896C332.8 896 170.666667 733.866667 170.666667 533.333333S332.8 170.666667 533.333333 170.666667 896 332.8 896 533.333333 733.866667 896 533.333333 896z m0-42.666667c174.933333 0 320-145.066667 320-320S708.266667 213.333333 533.333333 213.333333 213.333333 358.4 213.333333 533.333333 358.4 853.333333 533.333333 853.333333z"
    40.  
      fill="#444444" p-id="5571"></path>
    41.  
      </svg>
    42.  
      </div>
    43.  
       
    44.  
      <!-- 滚动条 -->
    45.  
      <!-- <div class="swiper-scrollbar"></div> -->
    46.  
      </div>
    47.  
      <script>
    48.  
      var mySwiper1 = new Swiper(".swiper-container", {
    49.  
      navigation: {
    50.  
      nextEl: ".swiper-button-next",
    51.  
      prevEl: ".swiper-button-prev",
    52.  
      },//前进后退按钮
    53.  
      loop: true,//无限循环
    54.  
      autoplay: true,//自动切换
    55.  
      keyboard: true,//键盘控制
    56.  
      zoom: true,//调焦,开启缩放功能
    57.  
      pagination: {
    58.  
      el: '.swiper-pagination',
    59.  
      dynamicBullets: true,
    60.  
      },//分页器
    61.  
      });
    62.  
      </script>
    63.  
      </body>
    64.  
      </html>
    学新通

四、效果展示 学新通 

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhffhjff
系列文章
更多 icon
同类精品
更多 icon
继续加载