最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Swiper JS slides per view and slides per column displaying incorrectly - Stack Overflow

programmeradmin4浏览0评论

I was trying to make a 2 rows of slides on bootstrap using swiper js using the demo given at the official page. However When I copied the code and ran on my browser it displayed like this

The code is exactly the same as the demo page

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

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

      .swiper-container {
      width: 100%;
      height: 100%;
      margin-left: auto;
      margin-right: auto;
     }
     .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;
      height: calc((100% - 30px) / 2);

      /* 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;
    }
  </style>
    </head>
    <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 class="swiper-slide">Slide 4</div>
      <div class="swiper-slide">Slide 5</div>
      <div class="swiper-slide">Slide 6</div>
      <div class="swiper-slide">Slide 7</div>
      <div class="swiper-slide">Slide 8</div>
      <div class="swiper-slide">Slide 9</div>
      <div class="swiper-slide">Slide 10</div>
      </div>
      <div class="swiper-pagination"></div>
     </div>

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

     <script>
      var swiper = new Swiper('.swiper-container', {
      slidesPerView: 3,
      slidesPerColumn: 2,
      spaceBetween: 30,
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
    });
  </script>
</body>
</html>

I tried changing the slides per view and slides per column but those were almost the same.

I was trying to make a 2 rows of slides on bootstrap using swiper js using the demo given at the official page. However When I copied the code and ran on my browser it displayed like this

The code is exactly the same as the demo page

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

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

      .swiper-container {
      width: 100%;
      height: 100%;
      margin-left: auto;
      margin-right: auto;
     }
     .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;
      height: calc((100% - 30px) / 2);

      /* 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;
    }
  </style>
    </head>
    <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 class="swiper-slide">Slide 4</div>
      <div class="swiper-slide">Slide 5</div>
      <div class="swiper-slide">Slide 6</div>
      <div class="swiper-slide">Slide 7</div>
      <div class="swiper-slide">Slide 8</div>
      <div class="swiper-slide">Slide 9</div>
      <div class="swiper-slide">Slide 10</div>
      </div>
      <div class="swiper-pagination"></div>
     </div>

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

     <script>
      var swiper = new Swiper('.swiper-container', {
      slidesPerView: 3,
      slidesPerColumn: 2,
      spaceBetween: 30,
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
    });
  </script>
</body>
</html>

I tried changing the slides per view and slides per column but those were almost the same.

Share Improve this question asked Mar 21, 2020 at 18:01 Joy DeyJoy Dey 5931 gold badge6 silver badges18 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 15

I had the same problem. It seems that the setting slidesPerColumn does not work. Then I was checking which CSS comes from the swiper css with those Swiper Slide settings:

.swiper-container-multirow-column > .swiper-wrapper {
   flex-direction: column;
 }

It turned out that when i overwrite the CSS, it works:

.swiper-container-multirow-column > .swiper-wrapper {
  flex-direction: inherit;
}

Or instead, add the following setting:

slidesPerColumnFill: 'row'

I hope that helps (even if it is a late answer on this topic).

If your using CDNs ->

<link rel="stylesheet"href="https://unpkg.com/swiper/swiper-bundle.min.css" >
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>

replace it with ->

<link rel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.min.js"></script>

That will do the trick..Apparently many options are not working with the previous CDN

Change container height

.swiper-container { height: 800px; }
发布评论

评论列表(0)

  1. 暂无评论