@@ -103,6 +103,7 @@ class Sticky {
103
103
*/
104
104
const nodeComputedStyle = getComputedStyle ( node ) ;
105
105
const nodeComputedProps = {
106
+ position : nodeComputedStyle . position ,
106
107
top : nodeComputedStyle . top ,
107
108
display : nodeComputedStyle . display ,
108
109
marginTop : nodeComputedStyle . marginTop ,
@@ -124,7 +125,16 @@ class Sticky {
124
125
this . _active = true ;
125
126
126
127
/*
127
- * 3. Get necessary node parameters
128
+ * 3. Check if the current node position is `sticky`. If it is, it means that the browser supports sticky positioning,
129
+ * but the polyfill was force-enabled. We set the node’s position to `static` before continuing, so that the node
130
+ * is in it’s initial position when we gather its params.
131
+ */
132
+ const originalPosition = node . style . position ;
133
+ if ( nodeComputedStyle . position == 'sticky' || nodeComputedStyle . position == '-webkit-sticky' )
134
+ node . style . position = 'static' ;
135
+
136
+ /*
137
+ * 4. Get necessary node parameters
128
138
*/
129
139
const referenceNode = node . parentNode ;
130
140
const parentNode = shadowRootExists && referenceNode instanceof ShadowRoot ? referenceNode . host : referenceNode ;
@@ -149,7 +159,7 @@ class Sticky {
149
159
right : - nodeWinOffset . right + parentWinOffset . right - parseNumeric ( parentComputedStyle . borderRightWidth )
150
160
} ;
151
161
this . _styles = {
152
- position : node . style . position ,
162
+ position : originalPosition ,
153
163
top : node . style . top ,
154
164
bottom : node . style . bottom ,
155
165
left : node . style . left ,
@@ -169,7 +179,7 @@ class Sticky {
169
179
} ;
170
180
171
181
/*
172
- * 4 . Ensure that the node will be positioned relatively to the parent node
182
+ * 5 . Ensure that the node will be positioned relatively to the parent node
173
183
*/
174
184
const parentPosition = parentComputedStyle . position ;
175
185
@@ -181,13 +191,13 @@ class Sticky {
181
191
}
182
192
183
193
/*
184
- * 5 . Recalc node position.
194
+ * 6 . Recalc node position.
185
195
* It’s important to do this before clone injection to avoid scrolling bug in Chrome.
186
196
*/
187
197
this . _recalcPosition ( ) ;
188
198
189
199
/*
190
- * 6 . Create a clone
200
+ * 7 . Create a clone
191
201
*/
192
202
const clone = this . _clone = { } ;
193
203
clone . node = document . createElement ( 'div' ) ;
0 commit comments