jQuery auto scroll vertically in a div

acctman picture acctman · Aug 28, 2012 · Viewed 60k times · Source

Can anyone suggest a good simple jQuery vertical autoscroller script? one that's not bloat, I just need for it to auto start and scroll 6 or more liin a div. i tried the jquery.autoscroll.js but couldn't get it to auto start.

$.fn.autoscroll.defaults = { 
   start: { 
      step: 50, 
      scroll: true, 
      direction: "down", 
      pauseOnHover: true 
   }, 
   delay: 5000, 
   ffrw: { 
      speed: "fast", 
      step: 100 
   } 
};

Answer

Robin Maben picture Robin Maben · Aug 28, 2012
var div = $('div.autoscrolling');
var scroller = setInterval(function(){
    var pos = div.scrollTop();
    div.scrollTop(++pos);
}, 100)​

Working Demo.

EDIT:

To stop scrolling when the div has scrolled to the bottom add the following check at the end of the above function() {} -

if($(this).scrollTop() + $(this).innerHeight() >= this.scrollHeight)
   clearInterval(scroller);
}