@@ -180,9 +180,15 @@ export default {
180
180
}
181
181
else {
182
182
if ( el . _sticky === true ) return
183
+ if ( process . env . NODE_ENV !== 'production' ) {
184
+ console . log ( `[vue-render] header add sticky` , el )
185
+ }
183
186
el . _sticky = true
184
187
if ( ! el . _placeholder ) {
185
- el . _placeholder = el . cloneNode ( true )
188
+ const placeholder = el . cloneNode ( true )
189
+ placeholder . _origNode = el
190
+ placeholder . classList . add ( 'weex-sticky-placeholder' )
191
+ el . _placeholder = placeholder
186
192
}
187
193
el . parentNode . insertBefore ( el . _placeholder , el )
188
194
el . style . width = window . getComputedStyle ( el ) . width
@@ -197,6 +203,9 @@ export default {
197
203
) {
198
204
return
199
205
}
206
+ if ( process . env . NODE_ENV !== 'production' ) {
207
+ console . log ( `[vue-render] header remove sticky` , el )
208
+ }
200
209
el . _sticky = false
201
210
el . parentNode . removeChild ( el . _placeholder )
202
211
el . classList . remove ( 'weex-sticky' )
@@ -205,12 +214,28 @@ export default {
205
214
reloadStickyChildren ( ) {
206
215
const container = this . $el
207
216
if ( ! container ) return
217
+ const stickyChildren = [ ]
208
218
const children = container . querySelectorAll ( '[sticky]' )
209
- this . _stickyChildren = children
210
219
for ( let i = 0 , l = children . length ; i < l ; i ++ ) {
211
220
const child = children [ i ]
212
- child . _initOffsetTop = child . offsetTop
221
+ if ( / w e e x - s t i c k y - p l a c e h o l d e r / . test ( child . className ) ) { // is a placeholder.
222
+ const origNode = child . _origNode
223
+ if (
224
+ ! origNode
225
+ || ! origNode . parentNode
226
+ || origNode . parentNode !== child . parentNode
227
+ ) {
228
+ child . parentNode . removeChild ( child )
229
+ }
230
+ }
231
+ else { // is a sticky node.
232
+ stickyChildren . push ( child )
233
+ if ( ! child . _sticky ) {
234
+ child . _initOffsetTop = child . offsetTop
235
+ }
236
+ }
213
237
}
238
+ this . _stickyChildren = stickyChildren
214
239
} ,
215
240
216
241
handleScroll ( event ) {
0 commit comments