Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit c1b715f

Browse files
pkarnykara
authored andcommitted
fix(util): scrollTop set on proper scroll target (#10549)
Closes #10272 #10432
1 parent 0151b4b commit c1b715f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/util/util.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
285285
var clientWidth = body.clientWidth;
286286
var hasVerticalScrollbar = body.scrollHeight > body.clientHeight + 1;
287287

288+
// Scroll may be set on <html> element (for example by overflow-y: scroll)
289+
// but Chrome is reporting the scrollTop position always on <body>.
290+
// scrollElement will allow to restore the scrollTop position to proper target.
291+
var scrollElement = documentElement.scrollTop > 0 ? documentElement : body;
292+
288293
if (hasVerticalScrollbar) {
289294
angular.element(body).css({
290295
position: 'fixed',
@@ -309,8 +314,8 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
309314
body.style.cssText = prevBodyStyle;
310315
documentElement.style.cssText = prevDocumentStyle;
311316

312-
// The body loses its scroll position while being fixed.
313-
body.scrollTop = viewportTop;
317+
// The scroll position while being fixed
318+
scrollElement.scrollTop = viewportTop;
314319
};
315320
}
316321

0 commit comments

Comments
 (0)