Skip to content

Commit ee15067

Browse files
committed
Make getOffset to public method
1 parent 0dad8ae commit ee15067

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ Here are some usefull public methods you can call via [`ref`](https://vuejs.org/
296296

297297
* `getSizes()`: get the total number of stored (rendered) items.
298298

299+
* `getOffset()`: get current scroll offset.
300+
299301
* `getClientSize()`: get wrapper element client viewport size (width or height).
300302

301303
* `getScrollSize()`: get all scroll size (scrollHeight or scrollWidth).

dist/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,21 @@
630630
getSizes: function getSizes() {
631631
return this.virtual.sizes.size;
632632
},
633+
// return current scroll offset
634+
getOffset: function getOffset() {
635+
var root = this.$refs.root;
636+
return root ? Math.ceil(root[this.directionKey]) : 0;
637+
},
638+
// return client viewport size
639+
getClientSize: function getClientSize() {
640+
var root = this.$refs.root;
641+
return root ? root[this.isHorizontal ? 'clientWidth' : 'clientHeight'] : 0;
642+
},
643+
// return all scroll size
644+
getScrollSize: function getScrollSize() {
645+
var root = this.$refs.root;
646+
return root ? root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight'] : 0;
647+
},
633648
// set current scroll position to a expectant offset
634649
scrollToOffset: function scrollToOffset(offset) {
635650
var root = this.$refs.root;
@@ -694,21 +709,6 @@
694709
return dataSource[_this2.dataKey];
695710
});
696711
},
697-
// return current scroll offset
698-
getOffset: function getOffset() {
699-
var root = this.$refs.root;
700-
return root ? Math.ceil(root[this.directionKey]) : 0;
701-
},
702-
// return client viewport size
703-
getClientSize: function getClientSize() {
704-
var root = this.$refs.root;
705-
return root ? root[this.isHorizontal ? 'clientWidth' : 'clientHeight'] : 0;
706-
},
707-
// return all scroll size
708-
getScrollSize: function getScrollSize() {
709-
var root = this.$refs.root;
710-
return root ? root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight'] : 0;
711-
},
712712
// event called when each item mounted or size changed
713713
onItemResized: function onItemResized(id, size) {
714714
this.virtual.saveSize(id, size);

src/index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ const VirtualList = Vue.component('virtual-list', {
8484
return this.virtual.sizes.size
8585
},
8686

87+
// return current scroll offset
88+
getOffset () {
89+
const { root } = this.$refs
90+
return root ? Math.ceil(root[this.directionKey]) : 0
91+
},
92+
93+
// return client viewport size
94+
getClientSize () {
95+
const { root } = this.$refs
96+
return root ? root[this.isHorizontal ? 'clientWidth' : 'clientHeight'] : 0
97+
},
98+
99+
// return all scroll size
100+
getScrollSize () {
101+
const { root } = this.$refs
102+
return root ? root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight'] : 0
103+
},
104+
87105
// set current scroll position to a expectant offset
88106
scrollToOffset (offset) {
89107
const { root } = this.$refs
@@ -147,24 +165,6 @@ const VirtualList = Vue.component('virtual-list', {
147165
return this.dataSources.map((dataSource) => dataSource[this.dataKey])
148166
},
149167

150-
// return current scroll offset
151-
getOffset () {
152-
const { root } = this.$refs
153-
return root ? Math.ceil(root[this.directionKey]) : 0
154-
},
155-
156-
// return client viewport size
157-
getClientSize () {
158-
const { root } = this.$refs
159-
return root ? root[this.isHorizontal ? 'clientWidth' : 'clientHeight'] : 0
160-
},
161-
162-
// return all scroll size
163-
getScrollSize () {
164-
const { root } = this.$refs
165-
return root ? root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight'] : 0
166-
},
167-
168168
// event called when each item mounted or size changed
169169
onItemResized (id, size) {
170170
this.virtual.saveSize(id, size)

0 commit comments

Comments
 (0)