Skip to content

Commit 2d4bc65

Browse files
committed
Implement #13
1 parent c89853a commit 2d4bc65

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

dist/vue-virtual-scroller.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/build.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/build.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-virtual-scroller",
33
"description": "Smooth scrolling for any amount of data",
4-
"version": "0.5.5",
4+
"version": "0.6.0",
55
"author": {
66
"name": "Guillaume Chau",
77
"email": "[email protected]"

src/components/VirtualScroller.vue

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export default {
7575
type: Boolean,
7676
default: false,
7777
},
78+
buffer: {
79+
type: [Number, String],
80+
default: 20,
81+
},
82+
poolSize: {
83+
type: [Number, String],
84+
default: 5,
85+
},
7886
},
7987
8088
data: () => ({
@@ -140,27 +148,27 @@ export default {
140148
const l = this.items.length
141149
const scroll = this.getScroll()
142150
if (scroll) {
143-
let startIndex = Math.floor(scroll.top / this.itemHeight)
144-
let endIndex = Math.ceil(scroll.bottom / this.itemHeight)
145-
startIndex -= 1
151+
let startIndex = Math.floor((Math.floor(scroll.top / this.itemHeight) - this.buffer) / this.poolSize) * this.poolSize
152+
let endIndex = Math.floor((Math.ceil(scroll.bottom / this.itemHeight) + this.buffer) / this.poolSize) * this.poolSize
146153
if (startIndex < 0) {
147154
startIndex = 0
148155
}
149-
endIndex += 2
150156
if (endIndex > l) {
151157
endIndex = l
152158
}
153-
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex)
154-
this._startIndex = startIndex
155-
this._endIndex = endIndex
156-
this.visibleItems = this.items.slice(startIndex, endIndex)
157-
this.itemContainerStyle = {
158-
height: l * this.itemHeight + 'px',
159-
}
160-
this.itemsStyle = {
161-
marginTop: startIndex * this.itemHeight + 'px',
159+
if (startIndex !== this._startIndex || endIndex !== this.endIndex) {
160+
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex)
161+
this._startIndex = startIndex
162+
this._endIndex = endIndex
163+
this.visibleItems = this.items.slice(startIndex, endIndex)
164+
this.itemContainerStyle = {
165+
height: l * this.itemHeight + 'px',
166+
}
167+
this.itemsStyle = {
168+
marginTop: startIndex * this.itemHeight + 'px',
169+
}
170+
this.$forceUpdate()
162171
}
163-
this.$forceUpdate()
164172
}
165173
},
166174

0 commit comments

Comments
 (0)