您必须将renderCustom函数放入分页中,如下所示:
var names = [];
$(".swiper-wrapper .swiper-slide").each(function(i) {
names.push($(this).data("name"));
});
var swiper1 = new Swiper('.swiper-container', {
pagination: {
el: '.swiper-pagination1',
type: 'custom',
renderCustom: function(swiper, current, total) {
var text = "<span class='pContainer' style='background-color:transperent;text-align: center;width:100%; display:block'>";
for (let i = 1; i <= total; i++) {
//alert(total);
if (current == i) {
text += "<span style='display:inline-block;border-top:3px solid #afd869;text-align:left;margin-right:4px;width: 20%;color:#afd869;padding:5px;'>" + names[i-1] + "</span>";
}
else {
text += "<span style='display:inline-block;border-top:3px solid white;text-align:left; margin-right:4px;width: 20%;color:white;padding:5px;'>" + names[i] + "</span>";
}
}
text += "</span>";
return text;
}
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
});
并将风格延伸。swiper分页自定义如下:
.swiper-pagination-custom{
position: absolute;
bottom: 0;
z-index: 10;
}