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 8152489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:43:46+00:00 2026-06-06T15:43:46+00:00

I am using the following code on a website to imitate smooth scrolling: function

  • 0

I am using the following code on a website to imitate smooth scrolling:

function scrollWindow() {
    // window.scrollBy(1040,0)
    var timerID = setInterval(function() {
        window.scrollBy(104, 0);
        if( window.pageXOffset >= 1040 ) clearInterval(timerID);
    }, 10);
}

However, after clicking Scroll (the scrollWindow function) the page scrolls 1040 like it should.

Any subsequent time, it does not work, unless i manually scroll back to the beginning.

Would i be right in thinking that if( window.pageXOffset >= 1040 ) is canceling it because although it hasn’t moved 1040, it is past that point on the page?

If so, how can i solve this?

  • 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-06T15:43:48+00:00Added an answer on June 6, 2026 at 3:43 pm

    Yes, your assessment is correct; but it could be corrected with a twist in the approach:

    function scrollWindow() {
        var scrolledSoFar = 0;
        var scrollStep = 104;
        var scrollEnd  = 1040;
        var timerID = setInterval(function() {
            window.scrollBy(scrollStep, 0);
            scrolledSoFar += scrollStep;
            if( scrolledSoFar >= scrollEnd ) clearInterval(timerID);
        }, 10);
    }
    

    Update
    Another pitfall in the code is that you are executing scrollBy before checking for the condition. So on your page, even after you have scrolled past 1040, clicking scroll will move the page by one scrollStep amount. To prevent that, this order is better:

    function scrollWindow() {
        var scrolledSoFar = 0;
        var scrollStep = 104;
        var scrollEnd  = 1040;
        var timerID = setInterval(function() {
            if( scrolledSoFar < scrollEnd ) {
                window.scrollBy(scrollStep, 0);
                scrolledSoFar += scrollStep;
            } else {
                clearInterval(timerID);
            }
        }, 10);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following code to check whether a check box on my website
I am using the following code to login to asp website but it doesnt
I am using the following code to fetch html source website. private string Extract_Source(string
I am using the following code to get an XML data from a website
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I am using the following code to add Facebook Like button to my website
I'm considering using the following code during a website launch phase to show users
I am using the following code to ping a website to check for connectivity.
I'm using the following code on my WordPress install: function add_glossary_links($content) { global $wpdb,
Using the guide on JSoup's website I wrote the following code: @Override public void

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.