Autoscroll to bottom of page then top and repeat

TheGambit picture TheGambit · Sep 18, 2012 · Viewed 19.9k times · Source

I have created a dashboard which echos out all the rows but I want an auto scroll which will slowly scroll down the bottom of the page and then scroll slowly back to the top and repeat. I have googled this and can't get a working code. I have been looking for jQuery codes but anything will do.

Because the page will adjust all the time it cant have fixed height scroll.

Not sure if you need more information but if you do I will update this question.

Regards Gambit

Answer

TimTastic picture TimTastic · Sep 18, 2012

You could use something like this.

//run instantly and then goes after (setTimeout interval)

    $("html, body").animate({ scrollTop: $(document).height() }, 4000);
    setTimeout(function() {
       $('html, body').animate({scrollTop:0}, 4000); 
    },4000);
  var scrolltopbottom =  setInterval(function(){
         // 4000 - it will take 4 secound in total from the top of the page to the bottom
    $("html, body").animate({ scrollTop: $(document).height() }, 4000);
    setTimeout(function() {
       $('html, body').animate({scrollTop:0}, 4000); 
    },4000);

    },8000);

​//Use this to stop the scroller -> clearInterval(scrolltopbottom);

Example: http://jsfiddle.net/NaP8D/11/