Skip to content

Commit 4b3f1b7

Browse files
committed
fix rounding issue when delta is less than 0
1 parent 2e2dc57 commit 4b3f1b7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

jquery.mousewheel.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565

6666
function handler(event) {
67-
var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0, absDeltaXY = 0;
67+
var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0, absDeltaXY = 0, fn;
6868
event = $.event.fix(orgEvent);
6969
event.type = "mousewheel";
7070

@@ -86,14 +86,20 @@
8686
if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; }
8787
if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX * -1; }
8888

89+
// Look for lowest delta to normalize the delta values
8990
absDelta = Math.abs(delta);
9091
if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; }
91-
9292
absDeltaXY = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
9393
if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; }
9494

95+
// Get a whole value for the deltas
96+
fn = delta > 0 ? 'floor' : 'ceil';
97+
delta = Math[fn](delta/lowestDelta);
98+
deltaX = Math[fn](deltaX/lowestDeltaXY);
99+
deltaY = Math[fn](deltaY/lowestDeltaXY);
100+
95101
// Add event and delta to the front of the arguments
96-
args.unshift(event, Math.floor(delta/lowestDelta), Math.floor(deltaX/lowestDeltaXY), Math.floor(deltaY/lowestDeltaXY));
102+
args.unshift(event, delta, deltaX, deltaY);
97103

98104
return ($.event.dispatch || $.event.handle).apply(this, args);
99105
}

0 commit comments

Comments
 (0)