gpt4 book ai didi

javascript - Swiper 轮播 SlidesPerView 无法正常工作

转载 作者:行者123 更新时间:2023-11-28 15:02:45 26 4
gpt4 key购买 nike

我有一张幻灯片,但我的幻灯片重复了三项!如何停止重复幻灯片?如果有 1 个幻灯片放映 1 个,如果有 2 个幻灯片放映 2 个,如果有 10 个幻灯片放映 10 个:|这是我的配置

var swiper = new Swiper('.slides-per-view', {
pagination: '.swiper-pagination',
speed: 800,
loop: true,
slidesPerView: 3,
centeredSlides: true,
spaceBetween: 30,
grabCursor: true,
paginationClickable: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev'
});

这是我的 Html 代码

<div class="swiper-container slides-per-view" dir="rtl">
<div class="swiper-wrapper">
<div class="swiper-slide">
<figure>
<a href="#"><img draggable="false" src="assets/pictures/activities/1.jpg" class="img-responsive" alt=""></a>
<figcaption class="text-light text-center"> Title</figcaption>
<div class="more text-center margin-bottom-30">
<p class="text-blue"><i class="fa fa-calendar"></i> Date</p>
<a href="" class="btn btn-info-border text-dark transition-5"> Read More </a>
</div>
</figure>
</div>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>

请看这张图片 enter image description here

最佳答案

如果您只有一个图 block ,则不能将loop 设置为true 并将slidesPerView 设置为3。所以你可以这样做:

var isLoop = true;

if($('.swiper-slide')).length < 3) {
isLoop = false;
}

var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
speed: 800,
loop: isLoop, //<--- set if loop is true or not
slidesPerView: 3,
centeredSlides: true,
spaceBetween: 30,
grabCursor: true,
paginationClickable: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev'
});

关于javascript - Swiper 轮播 SlidesPerView 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40280324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com