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);
});