Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!