25
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swiperのページ遷移ボタンをスライダーの横に出す&デザイン変更とか

Posted at

概要

Swiperのswiper-buttonを横に出すのに少しハマったのでメモ。
環境 : Swiper 3.4.0

  • ノーマルなやつ
<div class="swiper-container">
  <div class="swiper-wrapper">
      <div class="swiper-slide"></div>
      <div class="swiper-slide"></div>
      <div class="swiper-slide"></div>
  </div>
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>  
</div>
.swiper-container{
  width: 700px;
  height: 220px;
  margin: 100px 100px 0;
  padding: 10px;
  border: 1px solid #ccc;
}
.swiper-slide{
  background: red;
}

スクリーンショット 2018-01-04 2.22.02.png
以下jsは共通。

  • 横に出したやつ
    コツはswiper-button-hogeをswiper-containerと並べるとこ?
<div class="swiper-custom-parent">
  <div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide"></div>
        <div class="swiper-slide"></div>
        <div class="swiper-slide"></div>
    </div>
  </div>
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>  
</div>
.swiper-custom-parent{
  border: 1px solid #ccc;
  margin: 100px 100px 0;
  width: 800px;
  position: relative;
}
.swiper-container{
  width: 700px;
  height: 220px;
  padding: 10px;
}
.swiper-slide{
  background: red;
}
var swiper1 = new Swiper ('.swiper-container', {
  loop: true,
  nextButton: '.swiper-button-next',
  prevButton: '.swiper-button-prev',
  centeredSlides: true,
  paginationClickable: true,
  slidesPerView: 3,
  spaceBetween: 20,
});

スクリーンショット 2018-01-04 2.28.19.png

  • ついでにFontAwesomeボタンのデザイン変更とか
    swiper-button-hoge以外のclassをボタンにしようとするとスライドしなくなっちゃうので注意。
<div class="swiper-custom-parent">
  <div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide"></div>
        <div class="swiper-slide"></div>
        <div class="swiper-slide"></div>
    </div>
  </div>
  <div class="swiper-button-prev swiper-custom-button">
    <i class="fa fa-angle-left"></i>
  </div>
  <div class="swiper-button-next swiper-custom-button">
    <i class="fa fa-angle-right"></i>
  </div>  
</div>
.swiper-custom-parent{
  border: 1px solid #ccc;
  margin: 100px 100px 0;
  width: 800px;
  position: relative;
}
.swiper-container{
  width: 700px;
  height: 220px;
  padding: 10px;
}
.swiper-slide{
  background: red;
}
.swiper-custom-button{
  background-image: none !important;
  background: blue;
  color: white;
  font-size: 36px;
  text-align: center;
  width: 24px !important;
  height: 64px !important;
  line-height: 64px;
}
.swiper-custom-button .fa{
  line-height: 62px;
}

スクリーンショット 2018-01-04 2.44.10.png

25
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?