実現したいこと
下記キャプチャのように中心にスライダーのアクティブ画像を表示し、左右にアクティブ画像に隣接する前後の要素の画像を1枚づつ見切らせて表示したい。
https://gyazo.com/c86fcc89613d7e7efe3bf351a578a49f
現在の状況
アクティブ画像の位置が中心からかなりズレてしまい、レイアウトが崩れてしまっている
https://gyazo.com/e2daab7be34497cb6e5631c7bbcd8add
該当箇所のコード
HTML
1<div class="main-visual"> 2 <div class="add-wrapper"> 3 <div class="swiper-container swiper1"> 4 <div class="swiper-wrapper"> 5 <div class="swiper-slide slide1"> 6 <img src="path/to/image.svg" class="mv-img"> 7 </div> 8 <div class="swiper-slide slide2"> 9 <img src="path/to/image.svg" class="mv-img"> 10 </div> 11 <div class="swiper-slide slide3"> 12 <img src="path/to/image.svg" class="mv-img"> 13 </div> 14 <div class="swiper-slide slide4"> 15 <img src="path/to/image.svg" class="mv-img"> 16 </div> 17 <div class="swiper-slide slide5"> 18 <img src="path/to/image.svg" class="mv-img"> 19 </div> 20 </div> 21 <!-- swiperのページネーション --> 22 <div class="swiper-pagination page1"></div> 23 <!-- ナビゲーション --> 24 <div class="swiper-button-prev prev1"></div> 25 <div class="swiper-button-next next1"></div> 26 </div> 27 </div> 28</div>
CSS
1.main-visual { 2 width: 100%; 3 height: 522px; 4 background-image: url(hoge); 5 background-repeat: repeat; 6 z-index: 0; 7 background-color: #F0F0F0; 8 overflow-x: hidden; 9 overflow-y: hidden; 10 position: relative; 11} 12 13.add-wrapper { 14 margin-left: auto; 15 margin-right: auto; 16 max-width: 900px; 17} 18 19.swiper1 { 20 width: 100%; 21 overflow: visible; 22 z-index: 1; 23 height: 520px; 24} 25 26.swiper1 .swiper-slide { 27 vertical-align: middle; 28 margin-top: 88px; 29} 30 31.swiper1 .swiper-slide .mv-img { 32 width: 670px !important; 33 height: 335px !important; 34} 35 36.swiper1 .swiper-slide-active { 37 height: 450px !important; 38 width: 900px !important; 39 margin-top: 30px; 40} 41 42.swiper1 .swiper-slide-active .mv-img { 43 height: 450px !important; 44 width: 900px !important; 45} 46 47.swiper1 .swiper-slide-prev, 48.swiper1 .swiper-slide-next { 49 width: 670px !important; 50 height: 335px !important; 51} 52 53.swiper1 .swiper-slide-prev::after, 54.swiper1 .swiper-slide-next::after { 55 content: ""; 56 position: absolute; 57 display: block; 58 top: 0; 59 left: 0; 60 width: 100%; 61 height: 100%; 62 background: rgba(0, 0, 0, 0.7); 63} 64 65.swiper1 .swiper-slide-prev .mv-img, 66.swiper1 .swiper-slide-next .mv-img { 67 width: 670px !important; 68 height: 335px !important; 69} 70 71.swiper1 .swiper-pagination { 72 width: 100%; 73 left: 0; 74 bottom: 10px; 75} 76 77.swiper1 .swiper-button-next{ 78 width: 32px; 79 height: 60px; 80} 81 82.swiper1 .swiper-button-prev{ 83 width: 32px; 84 height: 60px; 85} 86 87.swiper-pagination-bullet-active { 88 opacity: 1; 89 background: #91d539; 90}
JavaScript
1<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js"></script> 2<script> 3'use strict'; 4 // スライダーの設定 5window.addEventListener('load', function() { 6 var mySwiper = new Swiper ('.swiper1', { 7 loop: true, 8 slidesPerView: 1.5, 9 centeredSlides : true, 10 loopedSlides:5, 11 spaceBetween: 0, 12 breakpoints: { 13 960: { 14 slidesPerView: 1, 15 spaceBetween: 0 16 } 17 }, 18 navigation: { 19 nextEl: '.next1', 20 prevEl: '.prev1', 21 }, 22 pagination: { 23 el: '.page1', 24 }, 25 // autoplay: { 26 // delay: 3000, 27 // disableOnInteraction: false 28 // }, 29 speed: 500, 30 roundLengths: true, 31 }); 32}, false); 33</script>
centeredSlides が機能していないようでうまく想定通りのレイアウトになってくれません。
必要な情報が不足している場合にはご指摘いただければ助かります。
ご支援のほどよろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/26 06:23
2019/08/26 07:17 編集