Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(util): scrollTop set on proper scroll target (#10549)
Browse files Browse the repository at this point in the history
Closes #10272 #10432
  • Loading branch information
pkarny authored and kara committed Jul 18, 2017
1 parent 0151b4b commit c1b715f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/util/util.js
Expand Up @@ -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 <html> element (for example by overflow-y: scroll)
// but Chrome is reporting the scrollTop position always on <body>.
// 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',
Expand All @@ -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;
};
}

Expand Down

0 comments on commit c1b715f

Please sign in to comment.