From 65d81921f9e9b8b0f32f384b59dad3aba0bc31fc Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 25 Feb 2015 20:24:07 +0000 Subject: [PATCH] Further fixes to scrolling behaviour --- core/modules/utils/dom/scroller.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/modules/utils/dom/scroller.js b/core/modules/utils/dom/scroller.js index 1a69b9d91..91e66a0ae 100644 --- a/core/modules/utils/dom/scroller.js +++ b/core/modules/utils/dom/scroller.js @@ -72,24 +72,27 @@ PageScroller.prototype.scrollIntoView = function(element) { // currentPos/currentSize - position and size of the current scroll viewport // returns: new position of the scroll viewport var getEndPos = function(targetPos,targetSize,currentPos,currentSize) { + var newPos = currentPos; // If the target is entirely above/left of the current view, then scroll to its top/left if((targetPos + targetSize) <= (currentPos + 50)) { - return targetPos; + newPos = targetPos; // If the target is smaller than the window and the scroll position is too far up, then scroll till the target is at the bottom of the window } else if(targetSize < currentSize && currentPos < (targetPos + targetSize - currentSize)) { - return targetPos + targetSize - currentSize; + newPos = targetPos + targetSize - currentSize; // If the target is out of view below/right, then just scroll to the top/left } else if(targetPos > (currentPos + currentSize - 50)) { - return targetPos; - // Otherwise, stay where we are - } else { - return currentPos; + newPos = targetPos; } + // If we are scrolling within 50 pixels of the top/left then snap to zero + if(newPos < 50) { + newPos = 0; + } + return newPos; }, endX = getEndPos(bounds.left,bounds.width,scrollPosition.x,window.innerWidth), endY = getEndPos(bounds.top,bounds.height,scrollPosition.y,window.innerHeight); - // Only scroll if the position has changed, plus a special case that we won't scroll less than 50 pixels from the top of the window - if((endX !== scrollPosition.x || endY !== scrollPosition.y) && (scrollPosition.y !== 0 || endY > 50)) { + // Only scroll if the position has changed + if(endX !== scrollPosition.x || endY !== scrollPosition.y) { var self = this, drawFrame; drawFrame = function () {