@@ -18,9 +18,8 @@ import { PositionData } from './Types/PositionData';
18
18
* @returns object with a top and left value in the form `{number}px`
19
19
*/
20
20
function position ( options : IOptions ) : PositionData {
21
- const { _bodyRect, _anchorRect, _targetRect, scrollableParents } = initialisePrivateFields ( ) ;
22
-
23
- const myPos = Helpers . parse (
21
+ const { _bodyRect, _anchorRect, _targetRect } = initialisePrivateFields ( ) ,
22
+ myPos = Helpers . parse (
24
23
options . my ,
25
24
options . defaults
26
25
? Helpers . parse ( options . defaults . my )
@@ -44,7 +43,6 @@ function position(options: IOptions): PositionData {
44
43
return {
45
44
left : calculateLeft ( myPos , atPos ) . value . toString ( ) + 'px' ,
46
45
top : calculateTop ( myPos , atPos ) . value . toString ( ) + 'px' ,
47
- scrollableParents,
48
46
// @ts -ignore
49
47
...( options . debug === true
50
48
? { _bodyRect, _anchorRect, _targetRect }
@@ -57,7 +55,6 @@ function position(options: IOptions): PositionData {
57
55
return {
58
56
top : pos . top . toString ( ) + 'px' ,
59
57
left : pos . left . toString ( ) + 'px' ,
60
- scrollableParents,
61
58
// @ts -ignore
62
59
...( options . debug === true
63
60
? { _bodyRect, _anchorRect, _targetRect }
@@ -81,41 +78,33 @@ function position(options: IOptions): PositionData {
81
78
return '{}' ;
82
79
} ,
83
80
}
84
- : options . anchor . getBoundingClientRect ( ) ;
81
+ : options . anchor . getBoundingClientRect ( ) ,
82
+ originalDisplay = options . target . style . display ,
83
+ _targetRect = options . target . getBoundingClientRect ( ) ;
85
84
86
- const originalDisplay = options . target . style . display ;
87
85
options . target . style . display = 'block' ;
88
-
89
- const _targetRect = options . target . getBoundingClientRect ( ) ,
90
- scrollableParents : HTMLElement [ ] = [ ] ;
91
-
92
86
options . target . style . display = originalDisplay ;
93
87
94
88
// Adjust to scrollable regions
95
89
if ( options . anchor instanceof HTMLElement ) {
96
- let parent = options . anchor . parentElement ;
97
-
98
- while ( parent !== null && parent . tagName !== 'HTML' ) {
99
- // Check if scrollable
100
- if ( parent . scrollHeight > parent . clientHeight )
101
- scrollableParents . push ( parent )
102
-
103
- parent = parent . parentElement ;
104
- }
105
-
106
90
// Finally, adjust for window scroll position
107
91
const doc = document . documentElement ;
108
92
_anchorRect . y +=
109
- ( window . scrollY || doc . scrollTop ) - ( doc . clientTop || 0 ) ;
93
+ ( window . scrollY ||
94
+ document . documentElement . scrollTop ||
95
+ document . body . scrollTop ||
96
+ 0 ) - ( doc . clientTop || 0 ) ;
110
97
_anchorRect . x +=
111
- ( window . scrollX || doc . scrollLeft ) - ( doc . clientLeft || 0 ) ;
98
+ ( window . scrollX ||
99
+ document . documentElement . scrollLeft ||
100
+ document . body . scrollLeft ||
101
+ 0 ) - ( doc . clientLeft || 0 ) ;
112
102
}
113
103
114
104
return {
115
105
_bodyRect,
116
106
_anchorRect,
117
107
_targetRect,
118
- scrollableParents
119
108
} ;
120
109
}
121
110
0 commit comments