Kevin Kevin - 1 month ago 20
jQuery Question

Swiper Slider Pagination Class number + 1

i've been trying to create some slides using swipe slider with custom classes.

<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
<div class="swiper-slide">Slide 10</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>

<!-- Swiper JS -->
<script src="../dist/js/swiper.min.js"></script>

<!-- Initialize Swiper -->
<script>
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
paginationClickable: true,
paginationBulletRender: function (swiper, index, className) {
return '<span class="' + className + '">' + (index + 1) + '</span>';
}
});
</script>


The swipe pagination generates into

<span class="swiper-pagination-bullet">1</span>
<span class="swiper-pagination-bullet">2</span>
<span class="swiper-pagination-bullet">3</span>
<span class="swiper-pagination-bullet">4</span>
<span class="swiper-pagination-bullet">5</span>
<span class="swiper-pagination-bullet">6</span>


I want to have the div class swiper pagination into

<span class="swiper-pagination-bullet color-0"></span>
<span class="swiper-pagination-bullet color-1"></span>
<span class="swiper-pagination-bullet color-2"></span>


i don't know to add custom class of color-0, color-1, color-2. Thank you so much.

Answer Source
return '<span class="'+ className +' color-'+index+'" >'+(index+1)+'</span>';