我有以下不适用于ios的代码:
“paginationCustomRender”中的内容有误,但我无法弄明白。
在桌面和Android上运行良好
var swiperH = new Swiper('.swiper-container-h', {
pagination: '.swiper-pagination-h',
paginationClickable: true,
spaceBetween: 4,
keyboardControl: true,
slidesPerView: 'auto',
loop: true,
speed: 450,
centeredSlides: true,
grabCursor: false,
nextButton: '.h-next',
prevButton: '.h-prev',
preventClicks: false,
preventClicksPropagation: false,
simulateTouch: false,
pagination: '.pag-shoes',
paginationType: "custom",
paginationCustomRender: function(swiper, current, total) {
var names = [];
$(".swiper-slide-ratio").each(function(i) {
names.push($(this).data("name"));
});
var text = "<span>";
for (let i = 1; i <= total; i++) {
if (current == i) {
text += "<span>" + names[i] + "</span>";
}
}
text += "</span>";
return text;
}
});
答案 0 :(得分:-1)
也许不支持ES6语法?将let
更改为var
此外,数组从0开始,因此当i == total
时,名称[i]超出范围如果当前是基于1的使用
for (var i = 0; i < total; i++) {
if (current == (i+1)) {
text += "<span>" + names[i] + "</span>";
}
}