Как у swiper решить проблему с пагинацией 01, 02, 03 - 010 и т.д

Как сделать нормальное отображение пагинации должно быть 01 02 03 04 05 06 07 08 09 10 и т.д т,е 20 30 40

введите сюда описание изображения

var swiper = new Swiper(".mySwiper", {
      slidesPerView: 3,
      spaceBetween: 30,
  pagination: {
    el: '.swiper-pagination',
    clickable: true,
    renderBullet: function (index, className) {
        return '<span class="' + className + '">' + "0" + (index + 1) + "</span>";
    },
  },
    });
.swiper {
      width: 100%;
      height: 500px
    }
    .swiper-wrapper{
    padding-bottom: 50px;
    }
    .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: red;
      height: 200px;
    }

    .swiper-slide img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
.swiper-pagination-bullet {
    color: #18918a;
}
.swiper-pagination-bullet-active {
    color: #222;
}

.swiper-pagination-bullet-active::after {
    opacity: 1;
}
.swiper-pagination-bullet-active {
    padding-right: 82px;
    background-color: transparent;
    position: relative;
}
.swiper-pagination-bullet::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 33px;
    -webkit-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    transform: translateY(-50%);
    width: 54px;
    border-bottom: 1px solid #fff;
    opacity: 0;
    -webkit-transition: 0.5s all;
    -o-transition: 0.5s all;
    transition: 0.5s all;
}
.swiper-pagination-bullet {
    font-size: 14px;
    line-height: 100%;
    font-family: "Onest-Regular";
    background-color: transparent !important;
    opacity: 1;
    height: 14px;
    position: relative;
    -webkit-transition: 0.5s all;
    -o-transition: 0.5s all;
    transition: 0.5s all;
    width: 10px;
    z-index: 10;
}
.common-pagination {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    width: 100%;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    gap: 8px;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    top: 0 !important;
}
<link href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
  <div class="swiper mySwiper">
    <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 class="swiper-slide">Slide 11</div>
    </div>
    <div class="swiper-pagination common-pagination"></div>
  </div>


Ответы (1 шт):

Автор решения: De.Minov

Почитайте про padStart() и используйте его, когда нужно вначале числа устанавливать 0.

new Swiper(".mySwiper", {
  slidesPerView: 3,
  spaceBetween: 10,
  pagination: {
    el: '.swiper-pagination',
    clickable: true,
    renderBullet: (index, className) => {
      return `<span class="${className}">${(''+(index+1)).padStart(2, '0')}</span>`
    },
  },
});
@import url(https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css);

.swiper {
  width: 400px;
  height: 200px;
  user-select: none;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: red;
}

.swiper-pagination-bullet {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 20px;
  height: 20px;
  background-color: #ccc;
  font-size: 10px;
  color: #555;
  opacity: 1;
}

.swiper-pagination-bullet-active {
  background-color: #09f;
  color: #fff;
}
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>

<div class="swiper mySwiper">
  <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 class="swiper-slide">Slide 11</div>
    <div class="swiper-slide">Slide 13</div>
    <div class="swiper-slide">Slide 14</div>
    <div class="swiper-slide">Slide 15</div>
  </div>
  <div class="swiper-pagination"></div>
</div>

→ Ссылка