@@ -71,6 +71,10 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
71
71
type : Boolean ,
72
72
default : false
73
73
} ,
74
+ scrollelement : {
75
+ type : HTMLElement ,
76
+ default : null
77
+ } ,
74
78
start : {
75
79
type : Number ,
76
80
default : 0
@@ -145,6 +149,11 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
145
149
itemcount : function itemcount ( ) {
146
150
this . changeProp = 'itemcount' ;
147
151
this . itemModeForceRender ( ) ;
152
+ } ,
153
+ scrollelement : function scrollelement ( newScrollelement , oldScrollelement ) {
154
+ if ( this . pagemode ) return ;
155
+ if ( oldScrollelement ) this . removeScrollListener ( oldScrollelement ) ;
156
+ if ( newScrollelement ) this . addScrollListener ( newScrollelement ) ;
148
157
}
149
158
} ,
150
159
created : function created ( ) {
@@ -179,7 +188,9 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
179
188
} ,
180
189
mounted : function mounted ( ) {
181
190
if ( this . pagemode ) {
182
- window . addEventListener ( 'scroll' , this . debounce ? _debounce ( this . onScroll . bind ( this ) , this . debounce ) : this . onScroll , false ) ;
191
+ this . addScrollListener ( window ) ;
192
+ } else if ( this . scrollelement ) {
193
+ this . addScrollListener ( this . scrollelement ) ;
183
194
}
184
195
185
196
if ( this . start ) {
@@ -191,7 +202,9 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
191
202
} ,
192
203
beforeDestroy : function beforeDestroy ( ) {
193
204
if ( this . pagemode ) {
194
- window . removeEventListener ( 'scroll' , this . debounce ? _debounce ( this . onScroll . bind ( this ) , this . debounce ) : this . onScroll , false ) ;
205
+ this . removeScrollListener ( window ) ;
206
+ } else if ( this . scrollelement ) {
207
+ this . removeScrollListener ( this . scrollelement ) ;
195
208
}
196
209
} ,
197
210
// check if delta should update when props change.
@@ -215,10 +228,33 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
215
228
}
216
229
} ,
217
230
methods : {
231
+ // add pagemode/scrollelement scroll event listener
232
+ addScrollListener : function addScrollListener ( element ) {
233
+ this . scrollHandler = this . debounce ? _debounce ( this . onScroll . bind ( this ) , this . debounce ) : this . onScroll ;
234
+ element . addEventListener ( 'scroll' , this . scrollHandler , false ) ;
235
+ } ,
236
+ // remove pagemode/scrollelement scroll event listener
237
+ removeScrollListener : function removeScrollListener ( element ) {
238
+ element . removeEventListener ( 'scroll' , this . scrollHandler , false ) ;
239
+ } ,
218
240
onScroll : function onScroll ( event ) {
219
241
var delta = this . delta ;
220
242
var vsl = this . $refs . vsl ;
221
- var offset = this . pagemode ? window . pageYOffset : ( vsl . $el || vsl ) . scrollTop || 0 ;
243
+ var offset ;
244
+
245
+ if ( this . pagemode ) {
246
+ var elemRect = this . $el . getBoundingClientRect ( ) ;
247
+ offset = - elemRect . top ;
248
+ } else if ( this . scrollelement ) {
249
+ var scrollelementRect = this . scrollelement . getBoundingClientRect ( ) ;
250
+
251
+ var _elemRect = this . $el . getBoundingClientRect ( ) ;
252
+
253
+ offset = scrollelementRect . top - _elemRect . top ;
254
+ } else {
255
+ offset = ( vsl . $el || vsl ) . scrollTop || 0 ;
256
+ }
257
+
222
258
delta . direction = offset > delta . scrollTop ? 'D' : 'U' ;
223
259
delta . scrollTop = offset ;
224
260
@@ -431,6 +467,8 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
431
467
setScrollTop : function setScrollTop ( scrollTop ) {
432
468
if ( this . pagemode ) {
433
469
window . scrollTo ( 0 , scrollTop ) ;
470
+ } else if ( this . scrollelement ) {
471
+ this . scrollelement . scrollTo ( 0 , scrollTop ) ;
434
472
} else {
435
473
var vsl = this . $refs . vsl ;
436
474
@@ -475,14 +513,6 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
475
513
paddingBottom = 0 ;
476
514
}
477
515
478
- if ( this . pagemode && this . $el && this . $el . parentElement ) {
479
- var bodyRect = document . body . getBoundingClientRect ( ) ;
480
- var elemRect = this . $el . parentElement . getBoundingClientRect ( ) ;
481
- var offset = elemRect . top - bodyRect . top ;
482
- paddingTop -= offset ;
483
- if ( paddingTop < 0 ) paddingTop = 0 ;
484
- }
485
-
486
516
delta . paddingTop = paddingTop ;
487
517
delta . paddingBottom = paddingBottom ;
488
518
delta . offsetAll = allHeight - this . size * this . remain ;
@@ -521,7 +551,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
521
551
}
522
552
} , list ) ; // page mode just render list, no wraper.
523
553
524
- if ( this . pagemode ) {
554
+ if ( this . pagemode || this . scrollelement ) {
525
555
return renderList ;
526
556
}
527
557
0 commit comments