Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:13:11+00:00 2026-06-02T01:13:11+00:00

The goal of my script is that when user scrolls down, my page should

  • 0

The goal of my script is that when user scrolls down, my page should scroll to the next div. For this, the script distinguishes if the user scrolls up and down. After, when he scrolls, it should remove the class active of my first div and add to the next. Then it’s scrolling to the new div with the class active. The problem is that it’s working for the first scroll only, not the next.

My code:

$(window).load(function() {
    var tempScrollTop, currentScrollTop = 0;
    var $current = $("#container > .active");
    var next = $('.active').next();
    var prev = $('.active').prev();

    $(window).scroll(function() {
        currentScrollTop = $(window).scrollTop();

        if (tempScrollTop < currentScrollTop) { //scrolling down 
            $current.removeClass('active').next().addClass('active'); 
            $.scrollTo(next, 1000);
        }
        else if (tempScrollTop > currentScrollTop ) { //scrolling up
            $current.removeClass('active').prev().addClass('active');
            $.scrollTo(prev, 1000);
        }

        tempScrollTop = currentScrollTop;
    }); 
});

Can anybody help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:13:14+00:00Added an answer on June 2, 2026 at 1:13 am

    I found the answer

    var lastScrollTop = 0;
    var isDoingStuff = false;

    $(document).scroll(function(event) {
        //abandon 
        if(isDoingStuff) { return; }
    
        if ($(this).scrollTop() > lastScrollTop) {
            //console.log('down');
            $('.active').removeClass('active').next('div').addClass('active');
            isDoingStuff = true;
            $('html,body').animate( {scrollTop: $('.active').offset().top }, 1000, function() {
                setTimeout(function() {isDoingStuff = false;}, 100);
                console.log('off');
            });
        } else {
            //console.log('up');
        }
        lastScrollTop = $(this).scrollTop();
    })​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal behind this question is to create a portable Windows script/program that would
My goal is to use a script that will install an executable file on
For example, my goal is to test the code given here: PHP script that
Goal : After user saves data to my mysql DB, a JSON teaser of
My goal: each time a user selects text, and clicks a button, that text
My goal is to take HTML entered by an end user, remove certain unsafe
Every time I try to run my script I get this error, saying that
I'm designing a Form in Access 2003. My goal is that when the user
I have a script that on.DocumentReady posts data to another page. That page responds
Goal To use a CREATE TYPE statement in HSQLDB 2.0.0 to create a user-defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.