Skip to content

Commit 0e20857

Browse files
committed
Only look at the deltaY and deltaX for the lowestDelta and floor values
that are greater than or equal to 1
1 parent 36ece57 commit 0e20857

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

jquery.mousewheel.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
}
2020
}(function ($) {
2121

22-
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
23-
var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];
24-
var slice = Array.prototype.slice;
25-
var lowestDelta, lowestDeltaXY;
22+
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
23+
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
24+
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
25+
slice = Array.prototype.slice,
26+
lowestDelta;
2627

2728
if ( $.event.fixHooks ) {
2829
for ( var i = toFix.length; i; ) {
@@ -69,9 +70,7 @@
6970
delta = 0,
7071
deltaX = 0,
7172
deltaY = 0,
72-
absDelta = 0,
73-
absDeltaXY = 0,
74-
fn;
73+
absDelta = 0;
7574
event = $.event.fix(orgEvent);
7675
event.type = 'mousewheel';
7776

@@ -103,17 +102,16 @@
103102
// No change actually happened, no reason to go any further
104103
if ( deltaY === 0 && deltaX === 0 ) { return; }
105104

106-
// Look for lowest delta to normalize the delta values
107-
absDelta = Math.abs(delta);
108-
if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; }
109-
absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));
110-
if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; }
111-
112-
// Get a whole value for the deltas
113-
fn = delta > 0 ? 'floor' : 'ceil';
114-
delta = Math[fn](delta / lowestDelta);
115-
deltaX = Math[fn](deltaX / lowestDeltaXY);
116-
deltaY = Math[fn](deltaY / lowestDeltaXY);
105+
// Store lowest absolute delta to normalize the delta values
106+
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
107+
if ( !lowestDelta || absDelta < lowestDelta ) {
108+
lowestDelta = absDelta;
109+
}
110+
111+
// Get a whole, normalized value for the deltas
112+
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
113+
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
114+
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
117115

118116
// Add event and delta to the front of the arguments
119117
args.unshift(event, delta, deltaX, deltaY);

0 commit comments

Comments
 (0)