Skip to content

Commit a1c514f

Browse files
committed
Add bench props to control scroll performance.
1 parent 06b3833 commit a1c514f

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,19 @@ new Vue({
104104

105105
## Props type
106106

107-
<img height="180" src="https://tangbc.github.io/github-images/vitual-scroll-list-3.png">
107+
<img height="256" src="https://tangbc.github.io/github-images/vitual-scroll-list-4.png">
108108

109109
*Prop* | *Type* | *Required* | *Description* |
110110
:--- | :--- | :--- | :--- |
111111
| size | Number || Each list item height, currently only supports fixed height. |
112112
| remain | Number || How many items should be shown in virtual-list viewport, so `size` and `remain` will determine the virtual-list outside container height (size × remian). |
113+
| 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. |
113114
| start | Number | * | Default value is `0`, the initial scroll start index. It must be integer and in the range of list index, throws a warning if index does not exist. |
114-
| debounce | Number | * | Milliseconds of using `debounce` function to ensure scroll event doesn't fire so often that it bricks browser performance, it's disabled by default. |
115-
| rtag | String | * | Default value is `div`, the virtual-list's root HTMLElement tag name, in all case it's style is set to `display: block;` |
116-
| rclass | String | * | Default value is an empty string, the virtual-list's root HTMLElement tag's classes. Has the same API has [`v-bind:class`](https://vuejs.org/v2/guide/class-and-style.html) |
117-
| wtag | String | * | Default value is `div`, the virtual-list's item wrapper HTMLElement tag name, in all case it's style is set to `display: block;` |
118-
| wclass | String | * | Default value is an empty string, the virtual-list's item wrapper HTMLElement tag's classes. Has the same API has [`v-bind:class`](https://vuejs.org/v2/guide/class-and-style.html) |
115+
| 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. |
116+
| rtag | String | * | Default value is `div`, the virtual-list root HTMLElement tag name, in all case it's style is set to `display: block;` |
117+
| rclass | String | * | Default value is an empty string, the virtual-list root HTMLElement tag's classes. Has the same API has [`v-bind:class`](https://vuejs.org/v2/guide/class-and-style.html) |
118+
| wtag | String | * | Default value is `div`, the virtual-list item wrapper HTMLElement tag name, in all case it's style is set to `display: block;` |
119+
| wclass | String | * | Default value is an empty string, the virtual-list item wrapper HTMLElement tag's classes. Has the same API has [`v-bind:class`](https://vuejs.org/v2/guide/class-and-style.html) |
119120
| onscroll | Function | * | Called when virtual-list scroll event handling, param: `(e, scrollTop)`. |
120121
| totop | Function | * | Called when the virtual-list is scrolled to top. |
121122
| tobottom | Function | * | Called when the virtual-list is scrolled to bottom. |

index.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
wclass: { type: String, default: '' },
4646
start: { type: Number, default: 0 },
4747
debounce: { type: Number, default: 0 },
48+
bench: Number,
4849
totop: Function,
4950
tobottom: Function,
5051
onscroll: Function
@@ -57,9 +58,9 @@
5758
end: 0, // End index.
5859
total: 0, // All items count.
5960
keeps: 0, // Nums keeping in real dom.
60-
benchs: 0, // Nums scroll pass should force update.
61+
bench: 0, // Nums scroll pass should force update.
6162
scrollTop: 0, // Store scrollTop.
62-
scrollDirect: 'd', // Scroll direction.
63+
scrollDirect: 'd', // Store scroll direction.
6364
viewHeight: 0, // Container wrapper viewport height.
6465
allPadding: 0, // All padding of not-render-yet doms.
6566
paddingTop: 0, // Container wrapper real padding-top.
@@ -128,8 +129,8 @@
128129
start = zone.start
129130
}
130131

131-
// If scroll pass items within now benchs, do not update.
132-
if (!isOver && (overs > delta.start) && (overs - delta.start <= delta.benchs)) {
132+
// For better performance, if scroll pass items within now bench, do not update.
133+
if (!isOver && (overs > delta.start) && (overs - delta.start <= delta.bench)) {
133134
return
134135
}
135136

@@ -196,7 +197,6 @@
196197
}
197198

198199
var hasPadding = slots.length > delta.keeps
199-
200200
delta.total = slots.length
201201
delta.paddingTop = this.size * (hasPadding ? delta.start : 0)
202202
delta.allPadding = this.size * (hasPadding ? slots.length - delta.keeps : 0)
@@ -209,14 +209,11 @@
209209

210210
beforeMount: function () {
211211
var delta = this.delta
212-
var remain = this.remain
213-
var benchs = Math.round(remain / 2)
214-
215-
delta.benchs = benchs
216-
delta.keeps = remain + benchs
217-
delta.viewHeight = this.size * remain
218-
delta.start = this.start >= remain ? this.start : 0
219-
delta.end = this.start + remain + benchs
212+
delta.bench = this.bench || this.remain
213+
delta.keeps = this.remain + delta.bench
214+
delta.viewHeight = this.size * this.remain
215+
delta.start = this.start >= this.remain ? this.start : 0
216+
delta.end = this.start + this.remain + delta.bench
220217
},
221218

222219
mounted: function () {

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.4",
3+
"version": "1.1.5",
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)