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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:08:52+00:00 2026-06-04T08:08:52+00:00

Are there any alternatives that can be used in a function to scroll a

  • 0

Are there any alternatives that can be used in a function to scroll a browser to the top of the page? Right now I’m using: $('html, body').animate({scrollTop: '0px'}, 300);.

Is there maybe something else, or something that is not jQuery?

  • 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-04T08:08:54+00:00Added an answer on June 4, 2026 at 8:08 am

    Below is a pure JavaScript implementation of a scrollTop function. It uses setInterval as an asynchronous while loop that periodically decrements the pageYOffset value, which represents the scrollbar position relative to the top of the page.

    To clarify, a while loop would block other scripts on the page from running and would make the scroll to the top appear instant, irregardless of the step value. Whereas, a setInterval with a 50ms iteration would only block the page once every 50ms and would update the scrollbar UI after each individual iteration.

    The function takes a single parameter “step”, which determines the rate that the scrollbar moves to the top of the screen. The smaller the step, the slower the rate in which the scrollbar moves to the top.

    function scrollTop(step) {
        var start = window.pageYOffset;
        var count = 0;
        var intervalRef = setInterval( (function(interval, curOffset) {
            return function() {
                curOffset -= (interval * step);
                console.info("offset = " + curOffset);
                window.scrollTo(0, curOffset);
                console.info("pageYoffset = " + window.pageYOffset);
                count++;
                if(count > 150 || curOffset < 0) clearInterval(intervalRef);
            }
        })(step, start--), 50);
    }
    
    // scroll to the top from the middle of the page in about 5 seconds.
    scrollTop(5);
    
    // scroll to the top in about 1 second
    scrollTop(15);
    
    // scrolls to the top very fast!
    scrollTop(35);
    

    The interval is halted when the offset reaches 0, which means the scrollbar has reached the top of the page.

    However, the count checker is there to limit the action to just 150 iterations to prevent you from locking up your browser, in case you decide to modify it. Otherwise, you can remove that condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any alternative to the IIS Administrative UI that can be used to
var_export function causes an exception while argument has circular references. Are there any alternatives
Is there any alternative image manipulation library for .net? I would prefer something that
Are there any alternatives to The CMU Pronouncing Dictionary , commercial or open source?
Are there any alternatives to JSTL? One company I worked for 3 years ago
Are there any alternatives to the Open Source Job Scheduler ? I'm looking for
Are there any alternatives to py2exe?
Are there any alternatives to stat (which is found on most Unix systems) which
Is there any alternatives to the print statement for output in Python. Also, how
WinJS.UI.getControl is not defined in VS 11 Ultimate. Is there any alternatives there to

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.