Skip to content

Commit 06f7e25

Browse files
committed
Fixed page mode bugs #204 #205
1 parent eb3f5b2 commit 06f7e25

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,19 @@ const VirtualList = Vue.component('virtual-list', {
7070

7171
// in page mode we bind scroll event to document
7272
if (this.pageMode) {
73+
this.updatePageModeFront()
74+
7375
document.addEventListener('scroll', this.onScroll, {
7476
passive: false
7577
})
76-
77-
// taking root offsetTop or offsetLeft as slot header size
78-
const { root } = this.$refs
79-
if (root) {
80-
this.virtual.updateParam('slotHeaderSize', root[this.isHorizontal ? 'offsetLeft' : 'offsetTop'])
81-
}
8278
}
8379
},
8480

8581
beforeDestroy () {
8682
this.virtual.destroy()
83+
if (this.pageMode) {
84+
document.removeEventListener('scroll', this.onScroll)
85+
}
8786
},
8887

8988
methods: {
@@ -170,6 +169,18 @@ const VirtualList = Vue.component('virtual-list', {
170169
}
171170
},
172171

172+
// when using page mode we need update slot header size manually
173+
// taking root offset relative to the browser as slot header size
174+
updatePageModeFront () {
175+
const { root } = this.$refs
176+
if (root) {
177+
const rect = root.getBoundingClientRect()
178+
const { defaultView } = root.ownerDocument
179+
const offsetFront = this.isHorizontal ? (rect.left + defaultView.pageXOffset) : (rect.top + defaultView.pageYOffset)
180+
this.virtual.updateParam('slotHeaderSize', offsetFront)
181+
}
182+
},
183+
173184
// reset all state back to initial
174185
reset () {
175186
this.virtual.destroy()

0 commit comments

Comments
 (0)