Robin's answer didn’t quite do the trick for me for several reasons, so the extended version of his approach was changed here:
var div = $('.scrollbit'); $('.scrollbit').bind('scroll mousedown wheel DOMMouseScroll mousewheel keyup', function(evt) { if (evt.type === 'DOMMouseScroll' || evt.type === 'keyup' || evt.type === 'mousewheel') { } if (evt.originalEvent.detail < 0 || (evt.originalEvent.wheelDelta && evt.originalEvent.wheelDelta > 0)) { clearInterval(scrollbit); } if (evt.originalEvent.detail > 0 || (evt.originalEvent.wheelDelta && evt.originalEvent.wheelDelta < 0)) { clearInterval(scrollbit); } }); var scrollbit = setInterval(function(){ var pos = div.scrollTop(); if ((div.scrollTop() + div.innerHeight()) >= div[0].scrollHeight) { clearInterval(scrollbit); } div.scrollTop(pos + 1); }, 100);
using anonymous user1248475 here:
Determine if a user scroll event was generated.
and this answer:
fooobar.com/questions/527885 / ...
Hope this is useful for those who want to solve the problem of automatically scrolling divs using jquery and stopping when scrolling user manually.
source share