Skip to content

Commit 8474d6e

Browse files
committed
update on height change
1 parent 01b8929 commit 8474d6e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/VirtualList.html

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div ref:viewport on:scroll='refresh()' style='height: {height};'>
1+
<div ref:viewport on:scroll='refresh()' style='height: {height};' bind:offsetHeight="viewportHeight">
22
<div ref:container style='padding-top: {_top}px; padding-bottom: {_bottom}px;'>
33
{#each visible as item (item.index)}
44
<div class='row'>
@@ -54,7 +54,7 @@
5454
}
5555

5656
this.on('state', ({ changed, previous, current }) => {
57-
if (changed.items || changed.height || changed.itemHeight) {
57+
if (changed.items || changed.height || changed.itemHeight || changed.viewportHeight) {
5858
if (current.itemHeight && (changed.itemHeight || current.items.length > this.heightMap.length)) {
5959
this.heightMap = current.items.map(() => current.itemHeight);
6060
}
@@ -86,9 +86,7 @@
8686

8787
methods: {
8888
initialise() {
89-
const { items, itemHeight } = this.get();
90-
const { viewport } = this.refs;
91-
const viewportHeight = viewport.offsetHeight;
89+
const { items, itemHeight, viewportHeight } = this.get();
9290

9391
if (itemHeight) {
9492
this.heightMap = items.map(item => itemHeight);
@@ -121,8 +119,8 @@
121119
},
122120

123121
refresh() {
124-
const { items, start, end, itemHeight } = this.get();
125-
const { offsetHeight, scrollTop } = this.refs.viewport;
122+
const { items, start, end, itemHeight, viewportHeight } = this.get();
123+
const { scrollTop } = this.refs.viewport;
126124

127125
let paddingTop = 0;
128126
let offset = 0;
@@ -146,7 +144,7 @@
146144
const newStart = i++;
147145

148146
for (; i < items.length; i += 1) {
149-
if (offset >= scrollTop + offsetHeight) break;
147+
if (offset >= scrollTop + viewportHeight) break;
150148
offset += this.heightMap[i];
151149
}
152150

@@ -179,4 +177,4 @@
179177
}
180178
}
181179
};
182-
</script>
180+
</script>

0 commit comments

Comments
 (0)