|
1 | 1 | /*!
|
2 |
| - * vue-virtual-scroll-list v2.1.6 |
| 2 | + * vue-virtual-scroll-list v2.1.7 |
3 | 3 | * open source under the MIT license
|
4 | 4 | * https://github.com/tangbc/vue-virtual-scroll-list#readme
|
5 | 5 | */
|
|
113 | 113 | }, {
|
114 | 114 | key: "getOffset",
|
115 | 115 | value: function getOffset(start) {
|
116 |
| - return start < 1 ? 0 : this.getIndexOffset(start); |
| 116 | + return (start < 1 ? 0 : this.getIndexOffset(start)) + this.param.slotHeaderSize; |
117 | 117 | }
|
118 | 118 | }, {
|
119 | 119 | key: "updateParam",
|
|
407 | 407 | type: Number,
|
408 | 408 | "default": 0
|
409 | 409 | },
|
| 410 | + pageMode: { |
| 411 | + type: Boolean, |
| 412 | + "default": false |
| 413 | + }, |
410 | 414 | rootTag: {
|
411 | 415 | type: String,
|
412 | 416 | "default": 'div'
|
|
626 | 630 | this.scrollToIndex(this.start);
|
627 | 631 | } else if (this.offset) {
|
628 | 632 | this.scrollToOffset(this.offset);
|
| 633 | + } // in page mode we bind scroll event to document |
| 634 | + |
| 635 | + |
| 636 | + if (this.pageMode) { |
| 637 | + document.addEventListener('scroll', this.onScroll, { |
| 638 | + passive: false |
| 639 | + }); // taking root offsetTop or offsetLeft as slot header size |
| 640 | + |
| 641 | + var root = this.$refs.root; |
| 642 | + |
| 643 | + if (root) { |
| 644 | + this.virtual.updateParam('slotHeaderSize', root[this.isHorizontal ? 'offsetLeft' : 'offsetTop']); |
| 645 | + } |
629 | 646 | }
|
630 | 647 | },
|
631 | 648 | beforeDestroy: function beforeDestroy() {
|
|
642 | 659 | },
|
643 | 660 | // return current scroll offset
|
644 | 661 | getOffset: function getOffset() {
|
645 |
| - var root = this.$refs.root; |
646 |
| - return root ? Math.ceil(root[this.directionKey]) : 0; |
| 662 | + if (this.pageMode) { |
| 663 | + return document.documentElement[this.directionKey]; |
| 664 | + } else { |
| 665 | + var root = this.$refs.root; |
| 666 | + return root ? Math.ceil(root[this.directionKey]) : 0; |
| 667 | + } |
647 | 668 | },
|
648 | 669 | // return client viewport size
|
649 | 670 | getClientSize: function getClientSize() {
|
650 |
| - var root = this.$refs.root; |
651 |
| - return root ? root[this.isHorizontal ? 'clientWidth' : 'clientHeight'] : 0; |
| 671 | + var key = this.isHorizontal ? 'clientWidth' : 'clientHeight'; |
| 672 | + |
| 673 | + if (this.pageMode) { |
| 674 | + return document.documentElement[key]; |
| 675 | + } else { |
| 676 | + var root = this.$refs.root; |
| 677 | + return root ? root[key] : 0; |
| 678 | + } |
652 | 679 | },
|
653 | 680 | // return all scroll size
|
654 | 681 | getScrollSize: function getScrollSize() {
|
655 |
| - var root = this.$refs.root; |
656 |
| - return root ? root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight'] : 0; |
| 682 | + var key = this.isHorizontal ? 'scrollWidth' : 'scrollHeight'; |
| 683 | + |
| 684 | + if (this.pageMode) { |
| 685 | + return document.documentElement[key]; |
| 686 | + } else { |
| 687 | + var root = this.$refs.root; |
| 688 | + return root ? root[key] : 0; |
| 689 | + } |
657 | 690 | },
|
658 | 691 | // set current scroll position to a expectant offset
|
659 | 692 | scrollToOffset: function scrollToOffset(offset) {
|
660 |
| - var root = this.$refs.root; |
| 693 | + if (this.pageMode) { |
| 694 | + document.documentElement[this.directionKey] = offset; |
| 695 | + } else { |
| 696 | + var root = this.$refs.root; |
661 | 697 |
|
662 |
| - if (root) { |
663 |
| - root[this.directionKey] = offset || 0; |
| 698 | + if (root) { |
| 699 | + root[this.directionKey] = offset; |
| 700 | + } |
664 | 701 | }
|
665 | 702 | },
|
666 | 703 | // set current scroll position to a expectant index
|
|
819 | 856 | padFront = _this$range2.padFront,
|
820 | 857 | padBehind = _this$range2.padBehind;
|
821 | 858 | var isHorizontal = this.isHorizontal,
|
| 859 | + pageMode = this.pageMode, |
822 | 860 | rootTag = this.rootTag,
|
823 | 861 | wrapTag = this.wrapTag,
|
824 | 862 | wrapClass = this.wrapClass,
|
|
836 | 874 | return h(rootTag, {
|
837 | 875 | ref: 'root',
|
838 | 876 | on: {
|
839 |
| - '&scroll': this.onScroll |
| 877 | + '&scroll': !pageMode && this.onScroll |
840 | 878 | }
|
841 | 879 | }, [// header slot
|
842 | 880 | header ? h(Slot, {
|
|
0 commit comments