Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery auto scroll vertically in a div

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 
   } 
};
like image 544
acctman Avatar asked Nov 30 '22 02:11

acctman


1 Answers

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);
}
like image 186
Robin Maben Avatar answered Dec 07 '22 12:12

Robin Maben