Reputation: 246
How would I, instead of 'scrolling' as much height as I want, a fixed height?
I.e a div is 50px
high and each time I scroll down I want to go down 50px
instead of just 'stopping' where you want.
Thanks in advance.
Upvotes: 0
Views: 85
Reputation: 3027
You can override scrolling of the div in such a way:
$("#scrollableContainer").scroll(function(e) {
//measure how far are you from the top of the scrollable container
var top = $("#scrollableContainer").scrollTop();
var scrollIncrement = 50; //50px
if (top % scrollIncrement!= 0) {
var delta;
//calculate delta you need to align the position with
if(e.detail > 0) {
//scroll down
delta = ((top / scrollIncrement) + 1) * scrollIncrement) - top;
}else {
//scroll up
delta = ((top / scrollIncrement) - 1) * scrollIncrement) - top;
}
$("#scrollableContainer").scrollTop(delta);
}
});
Upvotes: 1