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

159
Visualizações
JS code for disabling scrolling and replace with "scroll to next div on swipe down, previous div on swipe up"

I'm looking to find a way to be able to replace the default scrolling method for mobile devices of a website.

Tried to implement this code, but it fires every time there is a single swipe (which the scrolling to div also contains and therefore triggers again and again).

Thank you for any help!


    var timer = null;
window.addEventListener('scroll', function() {
    if(timer !== null) {
        clearTimeout(timer);        
    }
    timer = setTimeout(function() {
          // do something
    }, 150);
}, false);

  var lastScrollTop = 0;
  $(window).scroll(function(event){
  var st = $(this).scrollTop();

  if (st > lastScrollTop){
     // downscroll code
     console.log('down')

     var $target = $(".archive-blog-posts-wrapper.active").prev(".archive-blog-posts-wrapper");
     if ($target.length == 0) $target = $(".archive-blog-posts-wrapper:first");

     $("html, body").animate(
       {
         scrollTop: $target.offset().top,
       },
       "slow"
     );

     $(".active").removeClass("active");
     $target.addClass("active");
     
     
  } else {
    // upscroll code
    console.log('up')

    var $target = $(".archive-blog-posts-wrapper.active").next(".archive-blog-posts-wrapper");
    if ($target.length == 0) $target = $(".archive-blog-posts-wrapper:first");

    $("html, body").animate(
      {
        scrollTop: $target.offset().top,
      },
      "slow"
    );

    $(".active").removeClass("active");
    $target.addClass("active");
  }
  lastScrollTop = st;
  });
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