Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

概要

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

kur
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした