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 1
1
import { Injectable } from '@angular/core' ;
2
+ import { ViewportRuler } from './position/viewport-ruler' ;
2
3
3
4
/**
4
5
* Utilitity that allows for toggling scrolling of the viewport on/off.
@@ -15,18 +16,23 @@ export class DisableBodyScroll {
15
16
return this . _isActive ;
16
17
}
17
18
19
+ constructor ( private _viewportRuler : ViewportRuler ) { }
20
+
18
21
/**
19
22
* Disables scrolling if it hasn't been disabled already and if the body is scrollable.
20
23
*/
21
24
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 ) {
24
30
let html = document . documentElement ;
25
31
let initialBodyWidth = body . clientWidth ;
26
32
27
33
this . _htmlStyles = html . style . cssText || '' ;
28
34
this . _bodyStyles = body . style . cssText || '' ;
29
- this . _previousScrollPosition = window . scrollY || window . pageYOffset || 0 ;
35
+ this . _previousScrollPosition = this . _viewportRuler . getViewportScrollPosition ( ) . top ;
30
36
31
37
body . style . position = 'fixed' ;
32
38
body . style . width = '100%' ;
You can’t perform that action at this time.
0 commit comments