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

116
Visualizações
Swiper jumps to previously active slide on transitionEnd

I am trying to implement mouse drag module which would allow to transverse all the slides in swiper with single mouse drag equal to entire height of wrapper div (functionality similar to scrollbar but working no matter where you click). To do so I've implemented the following code:

function longDrag({ swiper, extendParams, on }) {
    let prevY = null;
    on('sliderMove', (swiper, e) => {
        if (!swiper.params.debugger) return;
        if (!prevY) prevY = e.clientY;
        if (prevY < e.clientY) {
            swiper.slideNext(0, false);
        }
        if (prevY > e.clientY) {
            swiper.slidePrev(0, false);
        }
        prevY = e.clientY;
    });
    on('slideChange', () => {
        if (!swiper.params.debugger) return;

        console.log(
        'slideChange',
         swiper.previousIndex,
         '->',
         swiper.activeIndex
         );
    });
}

When running the code the slideChange event fires indicating that active slide index changes, however in the browser slide does not change. In addition when mouse drag is finished the index of active slide returns to the first slide. I've tried modyfing some other events and it appears that this return to the first slide is caused by something just after transitionEnd event is emitted; adding

on('transitionEnd', (swiper) => {
    throw new Error("Not an error, just workaround")
  });

to longDrag function makes the script work as intended, however I do not think that this is the right way to do it.

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