I’ve got a button that is intended to scroll down a div when the mouse button is clicked and held on it . I thought this should work but it only scrolls one px per click as oppose to scrolling until the mouse up event .
code:
var howfar = 0;
$('#scrolldown').mousedown(function() {
howfar ++;
$('#scrollbox').scrollTop(howfar);
});
Keeping
mousedowncontinously doesn’t mean it will fire that event continously, it will only fire once. What you can do it start increasing the scrollTop oncemousedownevent triggers usingsetIntervaland then clear the interval onmouseupevent.Try something like this.
Demo