From 36f7799fca5a50e66de0f4d8a2215f3a9bed16a3 Mon Sep 17 00:00:00 2001 From: chriscbrock Date: Thu, 20 Feb 2014 09:21:39 +1300 Subject: [PATCH] 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. --- jquery.mousewheel.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index 63c968a84..6f5e70339 100755 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -87,7 +87,9 @@ delta = 0, deltaX = 0, deltaY = 0, - absDelta = 0; + absDelta = 0, + offsetX = 0, + offsetY = 0; event = $.event.fix(orgEvent); event.type = 'mousewheel'; @@ -160,11 +162,18 @@ delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta); deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta); deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta); + + // Normalise offsetX and offsetY properties + var boundingRect = this.getBoundingClientRect(); + offsetX = event.clientX - boundingRect.left; + offsetY = event.clientY - boundingRect.top; // Add information to the event object event.deltaX = deltaX; event.deltaY = deltaY; event.deltaFactor = lowestDelta; + event.offsetX = offsetX; + event.offsetY = offsetY; // Go ahead and set deltaMode to 0 since we converted to pixels // Although this is a little odd since we overwrite the deltaX/Y // properties with normalized deltas.