From 8474d6ec6b4e14a1f4a192d08280d0edd81a6fc9 Mon Sep 17 00:00:00 2001 From: mhkeller Date: Fri, 24 Aug 2018 17:37:42 -0700 Subject: [PATCH] update on height change --- src/VirtualList.html | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/VirtualList.html b/src/VirtualList.html index 308b4cb..77f14a9 100644 --- a/src/VirtualList.html +++ b/src/VirtualList.html @@ -1,4 +1,4 @@ -
+
{#each visible as item (item.index)}
@@ -54,7 +54,7 @@ } this.on('state', ({ changed, previous, current }) => { - if (changed.items || changed.height || changed.itemHeight) { + if (changed.items || changed.height || changed.itemHeight || changed.viewportHeight) { if (current.itemHeight && (changed.itemHeight || current.items.length > this.heightMap.length)) { this.heightMap = current.items.map(() => current.itemHeight); } @@ -86,9 +86,7 @@ methods: { initialise() { - const { items, itemHeight } = this.get(); - const { viewport } = this.refs; - const viewportHeight = viewport.offsetHeight; + const { items, itemHeight, viewportHeight } = this.get(); if (itemHeight) { this.heightMap = items.map(item => itemHeight); @@ -121,8 +119,8 @@ }, refresh() { - const { items, start, end, itemHeight } = this.get(); - const { offsetHeight, scrollTop } = this.refs.viewport; + const { items, start, end, itemHeight, viewportHeight } = this.get(); + const { scrollTop } = this.refs.viewport; let paddingTop = 0; let offset = 0; @@ -146,7 +144,7 @@ const newStart = i++; for (; i < items.length; i += 1) { - if (offset >= scrollTop + offsetHeight) break; + if (offset >= scrollTop + viewportHeight) break; offset += this.heightMap[i]; } @@ -179,4 +177,4 @@ } } }; - \ No newline at end of file +