From 535837e0178a7365a06287e063beeeadbcdab531 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 24 Mar 2014 22:31:03 +0000 Subject: [PATCH] Use client bounding rect rather than offset positions for computing scroll positions --- core/modules/utils/dom/scroller.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/core/modules/utils/dom/scroller.js b/core/modules/utils/dom/scroller.js index 2b087e3fa..107a74449 100644 --- a/core/modules/utils/dom/scroller.js +++ b/core/modules/utils/dom/scroller.js @@ -55,25 +55,20 @@ Handle a scroll event hitting the page document */ PageScroller.prototype.scrollIntoView = function(element) { var duration = $tw.utils.getAnimationDuration(); - // Get the offset bounds of the element - var bounds = { - left: element.offsetLeft, - top: element.offsetTop, - width: element.offsetWidth, - height: element.offsetHeight - }; - // Walk up the tree adjusting the offset bounds by each offsetParent - while(element.offsetParent) { - element = element.offsetParent; - bounds.left += element.offsetLeft; - bounds.top += element.offsetTop; - } // Now get ready to scroll the body this.cancelScroll(); this.startTime = new Date(); - var scrollPosition = $tw.utils.getScrollPosition(), - // We'll consider the horizontal and vertical scroll directions separately via this function - getEndPos = function(targetPos,targetSize,currentPos,currentSize) { + var scrollPosition = $tw.utils.getScrollPosition(); + // Get the client bounds of the element and adjust by the scroll position + var clientBounds = element.getBoundingClientRect(), + bounds = { + left: clientBounds.left + scrollPosition.x, + top: clientBounds.top + scrollPosition.y, + width: clientBounds.width, + height: clientBounds.height + }; + // We'll consider the horizontal and vertical scroll directions separately via this function + var getEndPos = function(targetPos,targetSize,currentPos,currentSize) { // If the target is above/left of the current view, then scroll to it's top/left if(targetPos <= currentPos) { return targetPos;