Swiper的基本使用——修改滚动条的样式

效果图如下:
Swiper的基本使用——修改滚动条的样式_第1张图片

Swiper基本使用方法参考官网链接

DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Swiper demotitle>
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">

  
  <link rel="stylesheet" href="../dist/css/swiper.min.css">

  
  <style>
    html, body {
      position: relative;
      height: 100%;
    }
    body {
      background: #eee;
      font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
      font-size: 14px;
      color:#000;
      margin: 0;
      padding: 0;
    }
    .swiper-container {
     width: 100%;
     height: 169px;
    }
    .swiper-wrapper{
      height: 92%;
    }
    .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;

      /* 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;
    }
    #swiper-scrollbar1{
      height: .4rem;
      background: #ccc;
      width: 20%;
      overflow: hidden;
      margin-top: .4rem;
      opacity: .4;
      transform: translateX(-50%);
      left: 50%;
    }
    .outer-item-box{
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px;
     box-sizing: border-box;
    }
    .item-box{
      border:1px solid #ccc;
      height: 100%;
      width: 100%;
     
    }
    .item-box:not(:last-child){
      margin-right: .6rem;
    }
  style>
head>
<body>
  
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide outer-item-box">
        <div class="item-box">
          1
        div>
        <div class="item-box">
          2
        div>
      
      div>
      <div class="swiper-slide outer-item-box">
        <div class="item-box">
          3
        div>
        <div class="item-box">
          4
        div>
      
      div>
      <div class="swiper-slide outer-item-box">
        <div class="item-box">
          5
        div>
        <div class="item-box">
          6
        div>
      
      div>
    div>
    
    <div class="swiper-scrollbar" id="swiper-scrollbar1">div>
  div>

  
  <script src="../dist/js/swiper.min.js">script>

  
  <script>
    var swiper = new Swiper('.swiper-container', {
        spaceBetween:10,   
        grabCursor:true,   //(我没看出有什么变化)
        scrollbar: {
          el: '.swiper-scrollbar',
          hide: false,  //不隐藏滚动条
          snapOnRelease: true,  //如果设置为false,释放滚动条时slide不会自动贴合(我没看出有什么变化)
          dragSize: 30,   //滚动条滑块的长度
          draggable: true,  //滚动条可拖拽可点击
      },
    });

    
  script>
body>
html>

Swiper的基本使用——修改滚动条的样式_第2张图片

你可能感兴趣的:(html,css,html,css)