Skip to content

Commit 36f7799

Browse files
committed
Normalise offsetX and offsetY on the event
According to the W3C Working Draft, offsetX and offsetY should be relative to the padding edge of the target element. The only browser using this convention is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does not support the properties. Normalizing to the border edge is easiest to do.
1 parent 87aa074 commit 36f7799

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

jquery.mousewheel.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@
8787
delta = 0,
8888
deltaX = 0,
8989
deltaY = 0,
90-
absDelta = 0;
90+
absDelta = 0,
91+
offsetX = 0,
92+
offsetY = 0;
9193
event = $.event.fix(orgEvent);
9294
event.type = 'mousewheel';
9395

@@ -160,11 +162,18 @@
160162
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
161163
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
162164
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
165+
166+
// Normalise offsetX and offsetY properties
167+
var boundingRect = this.getBoundingClientRect();
168+
offsetX = event.clientX - boundingRect.left;
169+
offsetY = event.clientY - boundingRect.top;
163170

164171
// Add information to the event object
165172
event.deltaX = deltaX;
166173
event.deltaY = deltaY;
167174
event.deltaFactor = lowestDelta;
175+
event.offsetX = offsetX;
176+
event.offsetY = offsetY;
168177
// Go ahead and set deltaMode to 0 since we converted to pixels
169178
// Although this is a little odd since we overwrite the deltaX/Y
170179
// properties with normalized deltas.

0 commit comments

Comments
 (0)