Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify how many pixels scroll moves on each step?

When I use mouse wheel to scroll content in div I want it to scroll by e.g., 30px each step or each mouse wheel tick w/e is the best solution.
I would prefer performance > ease i.e. I'm preferring javascript > jquery

like image 765
skmasq Avatar asked Dec 11 '22 11:12

skmasq


1 Answers

So I fiddled some solution of my own, you can see example here
Thanks Tom for leading me to this answer.

JS:

function wheel($div,deltaY){
   var step = 30;
   var pos = $div.scrollTop();
   var nextPos = pos + (step*(-deltaY))
   console.log("DelatY: " + deltaY + ", Step: " + step + ", nextPos: " + nextPos);
   $div.scrollTop(nextPos);
}

$('#test').bind('mousewheel', function(event, delta, deltaX, deltaY) {
    wheel($(this),deltaY);
    event.preventDefault();
});

Used libraries:

  • jQuery 1.8.3
  • jQuery mousewheel
like image 112
skmasq Avatar answered Jan 06 '23 18:01

skmasq