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

  • Home
  • SEARCH
  • 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 8970911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:49:28+00:00 2026-06-15T17:49:28+00:00

Im relatively new to JS coding, and can’t get this little number to work.

  • 0

Im relatively new to JS coding, and can’t get this little number to work. Can anyone tell me what I’m doing wrong?

My JavaScript is:

    incrementScroll = function() {
        window.scrollBy(0, 3) ;
    }

    startScrollLoop = function() {
        scrollLoopId = setInterval( "incrementScroll", 5) ; 
    }

    stopScrollLoop = function() {
        clearInterval( scrollLoopId ) ;
    }

And my HTML is:

<button onclick="startScrollLoop()">AUTO SCROLL</button>
<button onclick="stopScrollLoop ()">STOP SCROLL</button>

Again, many thanks for help. New to all of this and need to make a project work by morning.
Cheers.

  • 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-15T17:49:29+00:00Added an answer on June 15, 2026 at 5:49 pm

    The first argument to setInterval() should be a function reference, or non-ideally, a string to be eval()’d, which would be a complete function call with (). So remove the quotes:

    // Pass the reference to incrementScroll, 
    // not a quoted string containing its name.
    scrollLoopId = setInterval(incrementScroll, 5); 
    

    And to clear the scroll, you will need to define scrollLoopId at a higher scope with var.

    // Define outside the function so it is available
    // in scope of the stopScrollLoop() function when needed...
    var scrollLoopId;
    var startScrollLoop = function() {
        scrollLoopId = setInterval( incrementScroll, 5) ; 
    }
    

    Jsfiddle demo

    (uses a slower scroll speed to give you a chance to click the stop button in the middle of the text)

    Note that it is good practice to use the var keyword with each of these. even though they would end up at window scope anyway (assuming they’re not being defined inside another function).

    // Define with var
    var incrementScroll = function() {
      window.scrollBy(0, 3);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to coding; most of my work has been just simple GUI
I'm relatively new to this level of coding and am really hitting my wall
I'm relatively new to coding so please help me out here. The code will
Relatively new to JavaScript, so wondering what is the best approach to achive the
i am relatively experienced in Java coding but am new to C++. I have
I am a relatively new R user, and most of the complex coding (and
I'm relatively new to C# coding in the .NET framework. I'm using Visual studios
I'm relatively new to coding in general, first year CS student and all of
Caveat: I'm relatively new to coding as well as TextMate , so apologies if
I am new to posting and relatively new to coding in c++. My question

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.