code is as follows. If you directly use mySwiper
in onSlideChangeEnd
, an error message of mySwiper is undefined
will occur.
but this will not happen if a timer is added. And do not add loop attribute will not appear, may I ask why?
mySwiper = new Swiper(".swiper-container", {
direction: "vertical",
resistanceRatio: 0,
loop: true,
onSlideChangeEnd: function () {
setTimeout(() => {
var i = mySwiper;
console.log(i)
}, 10);
$(".swiper-slide").each(function () {
if ($(this).hasClass("swiper-slide-active")) { //
$(this).children().show();
$(this).siblings().children().hide();
}
});
if (i == $(".swiper-slide").length - 1) { //
$(".arrow").hide();
} else {
$(".arrow").show();
}
}
});