@bromo (BRM)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

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

1Answer

for文でループするイメージで、スライドが終了する時間、例えば11枚x2秒なら22秒後にタイマ起動しては?

0Like

Your answer might help someone💌