Skip to content

Commit 56b6dcb

Browse files
committed
Add some calculated data to onscroll params.
1 parent dd66f80 commit 56b6dcb

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ npm install vue-virtual-scroll-list --save
7777
</script>
7878
```
7979

80-
The `<Item>` component is included inside but defined outside the `<virtualList>` component. We see that `<virtualList>` does **not** rely on the `<Item>` component. So you can use virtual-list with any component freely.
80+
The `<Item>` component is included inside but defined outside the `<virtualList>` component, we see that `<virtualList>` does **not** rely on the `<Item>` component, so you can use virtual-list with any component freely.
8181

8282
#### Using by script include:
8383

@@ -120,15 +120,15 @@ new Vue({
120120
:--- | :--- | :--- | :--- |
121121
| size | Number || Each list item height, in variable height mode, this prop just use to calculate the virtual-list viewport height. |
122122
| remain | Number || How many items should be shown in virtual-list viewport, so `size` and `remain` determine the outside container viewport height (size × remian). |
123-
| bench | Number | * | Default value is equal to `remain`, unreached items count, not show in virtual-list viewport but exist in real DOM, the larger the bench, the higher the scroll performance will achieved. |
124123
| start | Number | * | Default value is `0`, the initial scroll start index. It must be integer and in the range of list index, if out of range it will be turned to `0` or the last one. |
124+
| bench | Number | * | Default value is equal to `remain`, unreached items count, not show in virtual-list viewport but exist in real DOM, the larger the bench, the higher the scroll performance will achieved. |
125125
| debounce | Number | * | **It's disabled by default**, milliseconds of using `debounce` function to ensure scroll event doesn't fire so often that it bricks browser performance. |
126126
| rtag | String | * | Default value is `div`, the virtual-list root element tag name, in all cases it's style is set to `display: block;` |
127127
| wtag | String | * | Default value is `div`, the virtual-list item wrapper element tag name, in all cases it's style is set to `display: block;` |
128128
| wclass | String | * | Default value is an empty string, the virtual-list item wrapper element class, has the same API with [`v-bind:class`](https://vuejs.org/v2/guide/class-and-style.html) |
129-
| onscroll | Function | * | Called when virtual-list scroll event handling, param: `(e, offset)`. |
130129
| totop | Function | * | Called when virtual-list is scrolled to top, no param. |
131130
| tobottom | Function | * | Called when virtual-list is scrolled to bottom, no param. |
131+
| onscroll | Function | * | Called when virtual-list is scrolling, param: `(e, { offset, offsetAll, start, end })`. |
132132
| variable | Function | * | For using virtual-list with variable height mode, this prop is a variable height getter function which is called with param: `(index)` when each item is ready to be calculated. |
133133

134134
### About variable height
@@ -138,7 +138,7 @@ In variable height mode, prop `size` is still required. All the index variable h
138138

139139
## Contributions
140140

141-
Welcome to improve vue-virtual-scroll-list by any pull request or issue.
141+
Welcome to improve vue-virtual-scroll-list with any issue, pull request or code review.
142142

143143

144144
## Changelogs

index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,34 @@
8888
var delta = this.delta
8989
var offset = this.$refs.vsl.scrollTop
9090

91-
if (!offset && delta.total) {
92-
this.triggerEvent('totop')
93-
}
94-
9591
if (delta.total > delta.keeps) {
9692
this.updateZone(offset)
9793
}
9894

99-
if (offset >= delta.offsetAll) {
100-
this.triggerEvent('tobottom')
95+
var offsetAll = delta.offsetAll
96+
if (this.onscroll) {
97+
this.onscroll(e, {
98+
offset: offset,
99+
offsetAll: offsetAll,
100+
start: delta.start,
101+
end: delta.end
102+
})
101103
}
102104

103-
if (this.onscroll) {
104-
this.onscroll(e, offset)
105+
if (!offset && delta.total) {
106+
this.triggerEvent('totop')
107+
}
108+
109+
if (offset >= offsetAll) {
110+
this.triggerEvent('tobottom')
105111
}
106112
},
107113

108114
// update render zone by scroll offset.
109115
updateZone: function (offset) {
110-
var overs
111-
if (this.variable) {
112-
overs = this.getVarOvers(offset)
113-
} else {
114-
overs = Math.floor(offset / this.size)
115-
}
116+
var overs = this.variable
117+
? this.getVarOvers(offset)
118+
: Math.floor(offset / this.size)
116119

117120
var delta = this.delta
118121
var zone = this.getZone(overs)
@@ -230,7 +233,7 @@
230233
var delta = this.delta
231234

232235
index = parseInt(index, 10)
233-
index = index < 0 ? 0 : index
236+
index = Math.max(0, index)
234237

235238
var lastStart = delta.total - delta.keeps
236239
var isLast = (index <= delta.total && index >= lastStart) || (index > delta.total)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-virtual-scroll-list",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "A vue (2.x) component that support big data and infinite loading by using virtual scroll list.",
55
"main": "index.js",
66
"files": [

0 commit comments

Comments
 (0)