From c89d6eac95f75f778ffea3411d1d27e99ede4976 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 6 Nov 2009 10:58:45 -0600 Subject: [PATCH] Fix incorrect offset in Element.viewportOffset on IE < 8. (cherry picked from commit 3afb0002cbd31726187338c5119657b76111f80c) --- src/dom/layout.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dom/layout.js b/src/dom/layout.js index d0d4dca..444da63 100644 --- a/src/dom/layout.js +++ b/src/dom/layout.js @@ -751,8 +751,13 @@ Element.addMethods({ viewportOffset: function(element) { element = $(element); - var rect = element.getBoundingClientRect(); - return new Element.Offset(rect.left, rect.top); + var rect = element.getBoundingClientRect(), + docEl = document.documentElement; + // The HTML element on IE < 8 has a 2px border by default, giving + // an incorrect offset. We correct this by subtracting clientTop + // and clientLeft. + return new Element.Offset(rect.top - docEl.clientTop, + rect.left - docEl.clientLeft); }, cumulativeOffset: function(element) {