Skip to content

Commit 68c31f8

Browse files
committed
Update Amatakasap's Page Mode for new version
1 parent 16f8d74 commit 68c31f8

File tree

3 files changed

+300
-85
lines changed

3 files changed

+300
-85
lines changed

dist/index.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
6767
type: String,
6868
default: ''
6969
},
70+
pageMode: {
71+
type: Boolean,
72+
default: false
73+
},
7074
start: {
7175
type: Number,
7276
default: 0
@@ -174,14 +178,23 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
174178
this.delta = delta;
175179
},
176180
mounted: function mounted() {
181+
if (this.pageMode) {
182+
window.addEventListener('scroll', this.debounce ? _debounce(this.onScroll.bind(this), this.debounce) : this.onScroll, false);
183+
}
184+
177185
if (this.start) {
178186
var start = this.getZone(this.start).start;
179187
this.setScrollTop(this.variable ? this.getVarOffset(start) : start * this.size);
180188
} else if (this.offset) {
181189
this.setScrollTop(this.offset);
182190
}
183191
},
184-
// check if delta should update when prorps change.
192+
beforeDestroy: function beforeDestroy() {
193+
if (this.pageMode) {
194+
window.removeEventListener('scroll', this.debounce ? _debounce(this.onScroll.bind(this), this.debounce) : this.onScroll, false);
195+
}
196+
},
197+
// check if delta should update when props change.
185198
beforeUpdate: function beforeUpdate() {
186199
var delta = this.delta;
187200
delta.keeps = this.remain + (this.bench || this.remain);
@@ -205,7 +218,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
205218
onScroll: function onScroll(event) {
206219
var delta = this.delta;
207220
var vsl = this.$refs.vsl;
208-
var offset = (vsl.$el || vsl).scrollTop || 0;
221+
var offset = this.pageMode ? window.pageYOffset : (vsl.$el || vsl).scrollTop || 0;
209222
delta.direction = offset > delta.scrollTop ? 'D' : 'U';
210223
delta.scrollTop = offset;
211224

@@ -416,10 +429,14 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
416429
},
417430
// set manual scroll top.
418431
setScrollTop: function setScrollTop(scrollTop) {
419-
var vsl = this.$refs.vsl;
432+
if (this.pageMode) {
433+
window.scrollTo(0, scrollTop);
434+
} else {
435+
var vsl = this.$refs.vsl;
420436

421-
if (vsl) {
422-
(vsl.$el || vsl).scrollTop = scrollTop;
437+
if (vsl) {
438+
(vsl.$el || vsl).scrollTop = scrollTop;
439+
}
423440
}
424441
},
425442
// filter the shown items base on `start` and `end`.
@@ -484,6 +501,18 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
484501
var _this$delta = this.delta,
485502
paddingTop = _this$delta.paddingTop,
486503
paddingBottom = _this$delta.paddingBottom;
504+
505+
if (this.pageMode) {
506+
return h(this.wtag, {
507+
'style': {
508+
'display': 'block',
509+
'padding-top': paddingTop + 'px',
510+
'padding-bottom': paddingBottom + 'px'
511+
},
512+
'class': this.wclass
513+
}, list);
514+
}
515+
487516
return h(this.rtag, {
488517
'ref': 'vsl',
489518
'style': {

0 commit comments

Comments
 (0)