Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Initialize multiple swipers.js on a single page by using Vanilla JS

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();
    });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda