Featured image of post Swiper 自定义分页器

Swiper 自定义分页器

Swiper 自定义分页器

2022-07-06-swiper1

/*包裹自定义分页器的div的位置等CSS样式*/
.swiper-pagination-custom {
  bottom: 10px;
  left: 0;
  width: 100%;
}
/*自定义分页器的样式,这个你自己想要什么样子自己写*/
.swiper-pagination-customs {
  width: 30px;
  height: 4px;
  display: inline-block;
  background: #000;
  opacity: 0.3;
  margin: 0 5px;
}
/*自定义分页器激活时的样式表现*/
.swiper-pagination-customs-active {
  opacity: 1;
  background-color: #f78e00;
}
var swiper = new Swiper(".mySwiper", {
  pagination: {
    el: ".swiper-pagination",
  },

  pagination: {
    el: ".swiper-pagination",
    clickable: true,
    type: "custom", //自定义分页器
    renderCustom: function (swiper, current, total) {
      var paginationHtml = " ";
      for (var i = 0; i < total; i++) {
        // 判断是不是激活焦点,是的话添加active类,不是就只添加基本样式类
        if (i === current - 1) {
          paginationHtml +=
            '<span class="swiper-pagination-customs swiper-pagination-customs-active" ></span>';
        } else {
          paginationHtml += '<span class="swiper-pagination-customs" ></span>';
        }
      }
      return paginationHtml;
    },
  },
});
Licensed under CC BY-NC-SA 4.0
本博客已稳定运行
发表了53篇文章 · 总计28.17k字
使用 Hugo 构建
主题 StackJimmy 设计