@@ -67,6 +67,19 @@ const VirtualList = Vue.component('virtual-list', {
6767 } else if ( this . offset ) {
6868 this . scrollToOffset ( this . offset )
6969 }
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+ }
7083 } ,
7184
7285 beforeDestroy ( ) {
@@ -86,27 +99,45 @@ const VirtualList = Vue.component('virtual-list', {
8699
87100 // return current scroll offset
88101 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+ }
91108 } ,
92109
93110 // return client viewport size
94111 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+ }
97119 } ,
98120
99121 // return all scroll size
100122 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+ }
103130 } ,
104131
105132 // set current scroll position to a expectant offset
106133 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+ }
110141 }
111142 } ,
112143
@@ -256,14 +287,14 @@ const VirtualList = Vue.component('virtual-list', {
256287 render ( h ) {
257288 const { header, footer } = this . $slots
258289 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
260291 const paddingStyle = { padding : isHorizontal ? `0px ${ padBehind } px 0px ${ padFront } px` : `${ padFront } px 0px ${ padBehind } px` }
261292 const wrapperStyle = wrapStyle ? Object . assign ( { } , wrapStyle , paddingStyle ) : paddingStyle
262293
263294 return h ( rootTag , {
264295 ref : 'root' ,
265296 on : {
266- '&scroll' : this . onScroll
297+ '&scroll' : ! pageMode && this . onScroll
267298 }
268299 } , [
269300 // header slot
0 commit comments