Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  39] [ 4]  / answers: 1 / hits: 19265  / 11 Years ago, mon, september 2, 2013, 12:00:00

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


More From » jquery

 Answers
12

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


[#75965] Friday, August 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;