First of all, the answers I found on this forum didn't solve my problem.
I'm using Swiper 8.0.7.
When I use classes below, only the one with class "slider-main__body" gets intitialized. If use a common class "swiper" they both include, the both swipers are initialized, however when I use controls (arrows and pagination) on the second slider, the images of the first one are moving. I found a few helpful suggestions, but none of them worked. I will appreciate your help.
function initSliders() {
if (document.querySelector('.slider-main__body')) {
new Swiper('.slider-main__body', {
modules: [Navigation, Pagination],
observer: true,
observeParents: true,
slidesPerView: 1,
spaceBetween: 32,
autoHeight: true,
speed: 800,
loop: true,
loopAdditionalSlides: 5,
preloadImages: false,
parallax: true,
pagination: {
el: '.controls-slider-main__dotts.swiper-pagination',
clickable: true,
},
navigation: {
prevEl: '.swiper-arrow.swiper-arrow-prev',
nextEl: '.swiper-arrow.swiper-arrow-next',
},
});
}
if (document.querySelector('.slider-rooms__body')) {
new Swiper('.slider-rooms__body', {
modules: [Navigation, Pagination],
observer: true,
observeParents: true,
slidesPerView: auto,
spaceBetween: 24,
autoHeight: true,
speed: 800,
loop: true,
loopAdditionalSlides: 5,
preloadImages: false,
parallax: true,
pagination: {
el: '#swiper-pagination',
clickable: true,
},
navigation: {
prevEl: '#swiper-arrow-prev',
nextEl: '#swiper-arrow-next',
},
});
}
}
window.addEventListener("load", function (e) {
initSliders();
});