Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: Automatic Smooth Scrolling

I have a page (that I control) that I would like it to have automatic smooth scrolling (at a controlled speed until the bottom of the page is reached).

Here is an example http://tim.theenchanter.com/2008/08/autoscroll-in-safari-firefox.html

Is there any way that could be done with jquery (not as a bookmarklet)?

like image 453
smw Avatar asked May 20 '26 06:05

smw


1 Answers

This example will take 30 seconds to scroll to the bottom of the page.

<a href="#bottom">start scrolling</a>

<p> lots of content here </p>

<h2 id="bottom">bottom of page</h2>

<script>
  var oneSecond = 1000;

  $('a').on('click', function() {

      $("html, body").animate({ 
          scrollTop: $(document).height() 
      }, 30 * oneSecond);

      return false;
  });
</script>

You can also see

http://css-tricks.com/snippets/jquery/smooth-scrolling/

and

jQuery Scroll to bottom of page/iframe

for other examples.

like image 86
Rich Hildebrand Avatar answered May 21 '26 20:05

Rich Hildebrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!