Skip to content

Commit 5a82180

Browse files
committed
fix sticky header while container updated.
1 parent af68634 commit 5a82180

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "weex-vue-render",
33
"description": "Web renderer for weex project written in Vue DSL.",
4-
"version": "1.0.23",
4+
"version": "1.0.24",
55
"license": "Apache-2.0",
66
"main": "dist/index.common.js",
77
"keywords": [

packages/weex-vue-render/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "weex-vue-render",
3-
"version": "1.0.23",
3+
"version": "1.0.24",
44
"description": "Web renderer for weex project written in Vue DSL.",
55
"license": "Apache-2.0",
66
"main": "dist/index.common.js",

src/components/scrollable/mixins/scrollable.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,15 @@ export default {
180180
}
181181
else {
182182
if (el._sticky === true) return
183+
if (process.env.NODE_ENV !== 'production') {
184+
console.log(`[vue-render] header add sticky`, el)
185+
}
183186
el._sticky = true
184187
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
186192
}
187193
el.parentNode.insertBefore(el._placeholder, el)
188194
el.style.width = window.getComputedStyle(el).width
@@ -197,6 +203,9 @@ export default {
197203
) {
198204
return
199205
}
206+
if (process.env.NODE_ENV !== 'production') {
207+
console.log(`[vue-render] header remove sticky`, el)
208+
}
200209
el._sticky = false
201210
el.parentNode.removeChild(el._placeholder)
202211
el.classList.remove('weex-sticky')
@@ -205,12 +214,28 @@ export default {
205214
reloadStickyChildren () {
206215
const container = this.$el
207216
if (!container) return
217+
const stickyChildren = []
208218
const children = container.querySelectorAll('[sticky]')
209-
this._stickyChildren = children
210219
for (let i = 0, l = children.length; i < l; i++) {
211220
const child = children[i]
212-
child._initOffsetTop = child.offsetTop
221+
if (/weex-sticky-placeholder/.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+
}
213237
}
238+
this._stickyChildren = stickyChildren
214239
},
215240

216241
handleScroll (event) {

0 commit comments

Comments
 (0)