File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 11import { Injectable } from '@angular/core' ;
2+ import { ViewportRuler } from './position/viewport-ruler' ;
23
34/**
45 * Utilitity that allows for toggling scrolling of the viewport on/off.
@@ -15,18 +16,23 @@ export class DisableBodyScroll {
1516 return this . _isActive ;
1617 }
1718
19+ constructor ( private _viewportRuler : ViewportRuler ) { }
20+
1821 /**
1922 * Disables scrolling if it hasn't been disabled already and if the body is scrollable.
2023 */
2124 activate ( ) : void {
22- if ( ! this . isActive && document . body . scrollHeight > window . innerHeight ) {
23- let body = document . body ;
25+ let body = document . body ;
26+ let bodyHeight = body . scrollHeight ;
27+ let viewportHeight = this . _viewportRuler . getViewportRect ( ) . height ;
28+
29+ if ( ! this . isActive && bodyHeight > viewportHeight ) {
2430 let html = document . documentElement ;
2531 let initialBodyWidth = body . clientWidth ;
2632
2733 this . _htmlStyles = html . style . cssText || '' ;
2834 this . _bodyStyles = body . style . cssText || '' ;
29- this . _previousScrollPosition = window . scrollY || window . pageYOffset || 0 ;
35+ this . _previousScrollPosition = this . _viewportRuler . getViewportScrollPosition ( ) . top ;
3036
3137 body . style . position = 'fixed' ;
3238 body . style . width = '100%' ;
You can’t perform that action at this time.
0 commit comments