swiperでループが効きません
解決したいこと
swiperで等速で流れる無限ループを作成したいのですが、
ループが実行されず止まってしまいます。
こちらの解決方法がわかる方いらっしゃいましたらご教授お願い致します。
該当するソースコード
const swiper = new Swiper(".swiper", {
loop:true,
speed:2000,
slidesPerView:'auto',
spaceBetween: 10,
autoplay: {
delay: 0,
}
});
例)
<div class="swiper">
<ul class="swiper-wrapper">
<li class="swiper-slide"></li>
<li class="swiper-slide"></li>
<li class="swiper-slide"></li>
<li class="swiper-slide"></li>
<li class="swiper-slide"></li>
<li class="swiper-slide"></li>
<li class="swiper-slide"></li>
</ul>
</div>
.swiper-wrapper {
transition-timing-function: linear;
}
.swiper-slide {
width:300px;
height:auto;
aspect-ratio:1/1;
}
.swiper-slide:nth-child(1) {
background:red;
}
.swiper-slide:nth-child(2) {
background:black;
}
.swiper-slide:nth-child(3) {
background:blue;
}
.swiper-slide:nth-child(4) {
background:green;
}
.swiper-slide:nth-child(5) {
background:yellow;
}
.swiper-slide:nth-child(6) {
background:pink;
}
.swiper-slide:nth-child(7) {
background:grey;
}
.swiper-slide:nth-child(8) {
background:white;
}
.swiper-slide:nth-child(9) {
background:skyblue;
}
.swiper-slide:nth-child(10) {
background:yellowgreen;
}
.swiper-slide:nth-child(11) {
background:purple;
}
自分で試したこと
headに
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.css"/>
footerに
<script src="//cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.js"></script>
のCDNで入れております。
サイトで調べていると等速で流れる無限ループを作るのに
slidesPerView:'auto'の記述をしている方がいましてこのコードを入れているのですが
slidesPerView:'auto'を入れたときだけループしません。
ですが、cssで指定した大きさでループさせたいです。
また、ループしても最後の最初のつなぎ目がスムーズにいきません。
解決方法わかる方いらっしゃいましたらご教授お願い致します。
0 likes