(一)swiper入門

weixin_34342992發表於2018-09-29

本節知識點

  • Swiper初始化

(1)Swiper初始化

  <link rel="stylesheet" href="css/swiper.min.css'">
  <script src="js/swiper.min.js"></script>

(2)Swiper例項

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="css/swiper.min.css">
  <script src="js/swiper.min.js"></script>
</head>
<style>
  * {
    margin: 0px;
    padding: 0px;
  }
  
  .swiper-container {
    width: 600px;
    height: 300px;
  }
  
  .swiper-slide {
    font-size: 50px;
  }
  
  .swiper-slide:nth-of-type(1) {
    background: blue;
  }
  
  .swiper-slide:nth-of-type(2) {
    background: red;
  }
  
  .swiper-slide:nth-of-type(3) {
    background: yellow;
  }
</style>

<body>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide">Slide 1</div>
      <div class="swiper-slide">Slide 2</div>
      <div class="swiper-slide">Slide 3</div>
    </div>
    <!-- 如果需要分頁器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要導航按鈕 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

    <!-- 如果需要滾動條 -->
    <div class="swiper-scrollbar"></div>
  </div>
</body>
<script>
  window.onload = function() {
    var mySwiper = new Swiper('.swiper-container', {
      direction: 'vertical', //垂直滑動
      loop: true, //迴圈
       // 如果需要分頁器
      pagination: '.swiper-pagination', //分頁器

      // 如果需要前進後退按鈕
      nextButton: '.swiper-button-next',  //下一個按鈕
      prevButton: '.swiper-button-prev', //上一個按鈕

      // 如果需要滾動條
      scrollbar: '.swiper-scrollbar',
    })
  }
</script>

</html>

對應效果圖

3709419-39ec1d828757593b.gif
111.gif

相關文章