I use swiper in centeredSlides mode and loop option is true. I want to when I click on a slide, that slide set as centered slide in swiper carousel. Swiper give me clicked slide index, but how to use it for change the centered slide?
These are my options:
slidesPerView: 4.5,
spaceBetween: 20,
updateOnWindowResize: true,
loop: true,
grabCursor: true,
centeredSlides: true,
centeredSlidesBounds: true,
initialSlide: 0,
on: {
click() {
console.log(this.clickedIndex);
},
},
Like this:
var mySwiper = new Swiper('.swiper-container', {
slidesPerView: 4.5,
spaceBetween: 20,
updateOnWindowResize: true,
loop: true,
grabCursor: true,
centeredSlides: true,
centeredSlidesBounds: true,
initialSlide: 0,
on: {
click() {
console.log('index', this.clickedIndex);
mySwiper.slideTo(this.clickedIndex);
},
},
});
Just set slideToClickedSlide
to true
and click on any slide will produce transition to this slide
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.