From c1b715f0094a4e6b7c1b49ecc94ec54ab441e97a Mon Sep 17 00:00:00 2001 From: Piotr Karny Date: Tue, 18 Jul 2017 18:52:18 +0200 Subject: [PATCH] fix(util): scrollTop set on proper scroll target (#10549) Closes #10272 #10432 --- src/core/util/util.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/util/util.js b/src/core/util/util.js index e31c4dd7cf2..552db013cf1 100644 --- a/src/core/util/util.js +++ b/src/core/util/util.js @@ -285,6 +285,11 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in var clientWidth = body.clientWidth; var hasVerticalScrollbar = body.scrollHeight > body.clientHeight + 1; + // Scroll may be set on element (for example by overflow-y: scroll) + // but Chrome is reporting the scrollTop position always on . + // scrollElement will allow to restore the scrollTop position to proper target. + var scrollElement = documentElement.scrollTop > 0 ? documentElement : body; + if (hasVerticalScrollbar) { angular.element(body).css({ position: 'fixed', @@ -309,8 +314,8 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in body.style.cssText = prevBodyStyle; documentElement.style.cssText = prevDocumentStyle; - // The body loses its scroll position while being fixed. - body.scrollTop = viewportTop; + // The scroll position while being fixed + scrollElement.scrollTop = viewportTop; }; }