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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:00:40+00:00 2026-06-09T04:00:40+00:00

so I have a div that looks like <div id=scroller>…</div> and inside this div

  • 0

so I have a div that looks like <div id="scroller">...</div> and inside this div is a bunch of content and the overflow is set to hidden.

I am attempt to make a smooth scrolling vertical div. I have a button on top of the div id='up' and a button on the bottom id='down'.

Right now when I click the up or down buttons the div will scroll, but only about 1 or 2 lines (each click).

Can someone please explain to me how I would bind this function so it continuously scrolls while the mouse is pressed down? Also, it feels more like a click up/down rather than a smooth scroll.

Is there a different function I should use rather than scrollTop()?

Heres a FIDDLE

Any help with this would be great!
Thanks in advance.

$(document).ready(function() {
    var timeoutId = 0;

function scrollIt(amount){
    $('#scroller').scrollTop($('#scroller').scrollTop()+amount);
}

$('#down').mousedown(function() {
    timeoutId = setTimeout(scrollIt(5), 1000);
}).bind('mouseleave', function() {
    clearTimeout(timeoutId);
});

$('#up').mousedown(function() {
    timeoutId = setTimeout(scrollIt(-5), 1000);
}).bind('mouseleave', function() {
    clearTimeout(timeoutId);
});
});

WORKING SOLUTION

$(document).ready(function() {
    var timeoutId = 0;

    function scrollIt(amount){
$('#scroller').scrollTop($('#scroller').scrollTop()+amount);
}

$('#down').mousedown(function() {
    timeoutId = setInterval(function(){scrollIt(5)}, 20);
}).bind('mouseup mouseleave', function() {
    clearInterval(timeoutId);
});

$('#up').mousedown(function() {
    timeoutId = setInterval(function(){scrollIt(-5)}, 20);
}).bind('mouseup mouseleave', function() {
    clearInterval(timeoutId);
});
});

HTML

<div class="scrollup" id="up">&nbsp;</div> 

 <div id="scroller" class="scroller buttongroup">  
    blah blah
    content blah
    blah blah
    content blah
</div>

<div class="scrolldown" id="down">&nbsp;</div> 
  • 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-09T04:00:42+00:00Added an answer on June 9, 2026 at 4:00 am

    You have two problems:

    1. the onmousedown event is only fired once, not repeatedly, so a single call to setTimeout will only happen once. The solution is to use setInterval (and clearInterval respectively) to have the method be repeatedly called until the interval is cleared

    2. The first parameter to setTimeout/setInterval must be a function. You’re actually passing the return value of scrollIt(5) which is undefined. You have to pass the actual function itself, i.e. just scrollIt. That of course leaves you with the problem of not being able to tell it whether to add 5 or subtract 5. You can solve that by simply wrapping the call in anonymous function and passing that:

      setInterval(function(){ scrollIt(5) }, 1000)
      

    Also, 1000 milliseconds is a very slow interval for something like scrolling. You need to knock that down to about 250. Here’s an updated fiddle with all these changes in effect.

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

Sidebar

Related Questions

I have some HTML that looks like this: <div class=product> Content In Here <div
I have a UL html list that looks like this: <div id=scroller> <ul> <li>item
I have html that looks like this with several items <div class=item> <p class=price>$388.00</p>
I have some HTML that looks like this: <div> <div class=value> <a href=# class=clicker>Some
If I have some HTML that looks like this: <div id=text> This is some
I have an HTML page that roughly looks like this: <div id=rolesRollerBody style=height: 309px;>
I have a form that looks kind of like this: <div> <div class=contact> <h1>Person's
I have a div that looks like this: <div> That's <div id=output></div> </div> The
I have a div that looks like this <div class=listItem jrFeatured> I want it
I have some HTML that looks like this: <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>

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.