我将如何,而不是“滚动”我想要的高度,一个固定的高度?
即一个 div50px
很高,每次我向下滚动时,我都想向下滚动,50px
而不是在你想要的地方“停止”。
提前致谢。
您可以通过以下方式覆盖 div 的滚动:
$("#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);
}
});