Можно ли как-нибудь изменить количество выводящихся элементов пагинации SwiperJS
Можно ли как-нибудь изменить количество выводящихся элементов пагинации SwiperJS. Желательно чтобы выводилось 3 года, а когда листаешь появлялись новые, а старые пропадали
var menu = ['1989', '1990', '1991', '1992', '1993', '1994']
var mySwiper = new Swiper ('.swiper-container', {
// If we need pagination
pagination: {
el: '.swiper-pagination',
clickable: true,
renderBullet: function (index, className) {
return '<span class="' + className + '">' + (menu[index]) + '</span>';
},
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
})
html, body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color:#000;
margin: 0;
padding: 0;
width: 50%;
margin: auto;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
.swiper-pagination {
position: absolute;
top: 10px;
right: 10px;
width: auto !important;
left: auto !important;
margin: 0;
}
.swiper-pagination-bullet {
padding: 5px 10px!important;
border-radius: 0!important;
width: auto!important;
height: 30px!important;
text-align: center!important;
line-height: 30px!important;
font-size: 12px!important;
color:#000!important;
opacity: 1!important;
background: rgba(0,0,0,0.2)!important;
}
.swiper-pagination-bullet-active {
color:#fff!important;
background: #007aff!important;
}
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<div class="swiper-container">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">Content</div>
<div class="swiper-slide" >Content</div>
<div class="swiper-slide">Content</div>
<div class="swiper-slide">Content</div>
<div class="swiper-slide">Content</div>
<div class="swiper-slide">Content</div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
Ответы (2 шт):
Автор решения: Dmitriy
→ Ссылка
https://moredez.ru/slider-swiper-api-20181018
вот это параметр кажется slidesPerView
Автор решения: Aziz Umarov
→ Ссылка
Так хотели? Думаю если посмотреть демки, то можно найти и более подходящее
var menu = ['1989', '1990', '1991', '1992', '1993', '1994']
var mySwiper = new Swiper ('.swiper-container', {
// If we need pagination
slidesPerView: 3,
pagination: {
el: '.swiper-pagination',
clickable: true,
renderBullet: function (index, className) {
return '<span class="' + className + '">' + (menu[index]) + '</span>';
},
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
})
html, body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color:#000;
margin: 0;
padding: 0;
width: 50%;
margin: auto;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
.swiper-pagination {
position: absolute;
top: 10px;
right: 10px;
width: auto !important;
left: auto !important;
margin: 0;
}
.swiper-pagination-bullet {
padding: 5px 10px!important;
border-radius: 0!important;
width: auto!important;
height: 30px!important;
text-align: center!important;
line-height: 30px!important;
font-size: 12px!important;
color:#000!important;
opacity: 1!important;
background: rgba(0,0,0,0.2)!important;
}
.swiper-pagination-bullet-active {
color:#fff!important;
background: #007aff!important;
}
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<div class="swiper-container">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">Content</div>
<div class="swiper-slide" >Content</div>
<div class="swiper-slide">Content</div>
<div class="swiper-slide">Content</div>
<div class="swiper-slide">Content</div>
<div class="swiper-slide">Content</div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>