function updateClasses({ $el, slides, activeIndex }) {
$el.find('.swiper-slide-prev-prev').removeClass('swiper-slide-prev-prev');
slides.eq(activeIndex).prev().prev().addClass('swiper-slide-prev-prev');
$el.find('.swiper-slide-next-next').removeClass('swiper-slide-next-next');
slides.eq(activeIndex).next().next().addClass('swiper-slide-next-next');
}
on: {
init() {
updateClasses(this);
},
slideChange() {
updateClasses(this);
},
},
function updateFraction(slider) {
const { params, activeIndex } = slider;
slider.$el
.find(`.${params.pagination.currentClass}`)
.text(`${activeIndex + 1} - ${activeIndex + params.slidesPerView}`);
slider.$el
.find(`.${params.pagination.totalClass}`)
.text(slider.slides.length);
}
on: {
init() {
setTimeout(updateFraction, 0, this);
},
slideChange() {
updateFraction(this);
},
resize() {
updateFraction(this);
},
},
function initSlider(el) {
if (!(el instanceof HTMLElement)) {
el = document.querySelector(el);
}
const slider = new Swiper(el.querySelector('.product-slider'), {
navigation: {
nextEl: el.querySelector('.swiper-button-next'),
prevEl: el.querySelector('.swiper-button-prev'),
},
spaceBetween: 10,
});
const thumbs = new Swiper(el.querySelector('.product-thumbs'), {
spaceBetween: 5,
centeredSlides: true,
slidesPerView: 4,
touchRatio: 0.2,
slideToClickedSlide: true,
direction: 'vertical',
});
slider.controller.control = thumbs;
thumbs.controller.control = slider;
return { slider, thumbs };
}
const
first = initSlider('.container-first'),
second = initSlider('.container-second');
document.querySelector('.set-slide').addEventListener('click', () => {
second.slider.slideTo(first.slider.realIndex);
});
document.querySelectorAll('.container').forEach(n => {
const slider = new Swiper(n.querySelector('.product-slider'), {
navigation: {
nextEl: n.querySelector('.swiper-button-next'),
prevEl: n.querySelector('.swiper-button-prev'),
},
spaceBetween: 10,
});
const thumbs = new Swiper(n.querySelector('.product-thumbs'), {
spaceBetween: 5,
centeredSlides: true,
slidesPerView: 4,
touchRatio: 0.2,
slideToClickedSlide: true,
direction: 'vertical',
});
slider.controller.control = thumbs;
thumbs.controller.control = slider;
});
document.querySelectorAll('.gallery').forEach(n => {
});
'.gallery-thumbs'
и '.gallery-top'
на n.querySelector('.gallery-thumbs')
и n.querySelector('.gallery-top')
соответственно. <swiper @click="onClick"
methods: {
onClick(e) {
const slide = e.target.closest('.swiper-slide');
if (slide) {
console.log(`slide ${slide.dataset.swiperSlideIndex} clicked`);
}
},
const swiperOptions = {
...
on: {
'init resize slideChangeTransitionStart'() {
$('.swiper-pagination').css({
top: $('.swiper-slide-active .head').height() + 30, /* или 40, или 50, или...
* на ваше усмотрение, это чтобы
* пагинация была чуть ниже заголовка,
* а не залезала на него
*/
});
},
},
};
el: '.slidernav'
el: this.querySelector('.slidernav')