@@ -67,6 +67,19 @@ const VirtualList = Vue.component('virtual-list', {
67
67
} else if ( this . offset ) {
68
68
this . scrollToOffset ( this . offset )
69
69
}
70
+
71
+ // in page mode we bind scroll event to document
72
+ if ( this . pageMode ) {
73
+ document . addEventListener ( 'scroll' , this . onScroll , {
74
+ passive : false
75
+ } )
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
+ }
82
+ }
70
83
} ,
71
84
72
85
beforeDestroy ( ) {
@@ -86,27 +99,45 @@ const VirtualList = Vue.component('virtual-list', {
86
99
87
100
// return current scroll offset
88
101
getOffset ( ) {
89
- const { root } = this . $refs
90
- return root ? Math . ceil ( root [ this . directionKey ] ) : 0
102
+ if ( this . pageMode ) {
103
+ return document . documentElement [ this . directionKey ]
104
+ } else {
105
+ const { root } = this . $refs
106
+ return root ? Math . ceil ( root [ this . directionKey ] ) : 0
107
+ }
91
108
} ,
92
109
93
110
// return client viewport size
94
111
getClientSize ( ) {
95
- const { root } = this . $refs
96
- return root ? root [ this . isHorizontal ? 'clientWidth' : 'clientHeight' ] : 0
112
+ const key = this . isHorizontal ? 'clientWidth' : 'clientHeight'
113
+ if ( this . pageMode ) {
114
+ return document . documentElement [ key ]
115
+ } else {
116
+ const { root } = this . $refs
117
+ return root ? root [ key ] : 0
118
+ }
97
119
} ,
98
120
99
121
// return all scroll size
100
122
getScrollSize ( ) {
101
- const { root } = this . $refs
102
- return root ? root [ this . isHorizontal ? 'scrollWidth' : 'scrollHeight' ] : 0
123
+ const key = this . isHorizontal ? 'scrollWidth' : 'scrollHeight'
124
+ if ( this . pageMode ) {
125
+ return document . documentElement [ key ]
126
+ } else {
127
+ const { root } = this . $refs
128
+ return root ? root [ key ] : 0
129
+ }
103
130
} ,
104
131
105
132
// set current scroll position to a expectant offset
106
133
scrollToOffset ( offset ) {
107
- const { root } = this . $refs
108
- if ( root ) {
109
- root [ this . directionKey ] = offset || 0
134
+ if ( this . pageMode ) {
135
+ document . documentElement [ this . directionKey ] = offset
136
+ } else {
137
+ const { root } = this . $refs
138
+ if ( root ) {
139
+ root [ this . directionKey ] = offset
140
+ }
110
141
}
111
142
} ,
112
143
@@ -256,14 +287,14 @@ const VirtualList = Vue.component('virtual-list', {
256
287
render ( h ) {
257
288
const { header, footer } = this . $slots
258
289
const { padFront, padBehind } = this . range
259
- const { isHorizontal, rootTag, wrapTag, wrapClass, wrapStyle, headerTag, headerClass, headerStyle, footerTag, footerClass, footerStyle } = this
290
+ const { isHorizontal, pageMode , rootTag, wrapTag, wrapClass, wrapStyle, headerTag, headerClass, headerStyle, footerTag, footerClass, footerStyle } = this
260
291
const paddingStyle = { padding : isHorizontal ? `0px ${ padBehind } px 0px ${ padFront } px` : `${ padFront } px 0px ${ padBehind } px` }
261
292
const wrapperStyle = wrapStyle ? Object . assign ( { } , wrapStyle , paddingStyle ) : paddingStyle
262
293
263
294
return h ( rootTag , {
264
295
ref : 'root' ,
265
296
on : {
266
- '&scroll' : this . onScroll
297
+ '&scroll' : ! pageMode && this . onScroll
267
298
}
268
299
} , [
269
300
// header slot
0 commit comments