pref: use translateY instead of traditional layout positioning (#639)
This commit is contained in:
1 parent
9460eec7e1
commit
bc476a5e4f
2 files changed
+16
-6
No files matched your search
@@ -45,6 +45,7 @@
|
|||||||
overscan={5}
|
overscan={5}
|
||||||
estimatedHeight={500}
|
estimatedHeight={500}
|
||||||
items={nodes}
|
items={nodes}
|
||||||
|
useGpu={false}
|
||||||
{initialOffset}
|
{initialOffset}
|
||||||
>
|
>
|
||||||
{#snippet item(index)}
|
{#snippet item(index)}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
debounceResize?: number
|
debounceResize?: number
|
||||||
useWindow?: boolean
|
useWindow?: boolean
|
||||||
height?: number
|
height?: number
|
||||||
|
useGpu?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
debounceResize = 100,
|
debounceResize = 100,
|
||||||
useWindow = true,
|
useWindow = true,
|
||||||
height = 0,
|
height = 0,
|
||||||
|
useGpu = true,
|
||||||
...rest
|
...rest
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
@@ -111,7 +113,6 @@
|
|||||||
|
|
||||||
function updateVisibleItems() {
|
function updateVisibleItems() {
|
||||||
if (!virtualListEl) return []
|
if (!virtualListEl) return []
|
||||||
|
|
||||||
viewportHeight = innerHeight?.current ?? 1000
|
viewportHeight = innerHeight?.current ?? 1000
|
||||||
const scrollTop = scrollY - initialOffset
|
const scrollTop = scrollY - initialOffset
|
||||||
|
|
||||||
@@ -223,14 +224,22 @@
|
|||||||
if (!useWindow) scrollY = virtualListEl?.scrollTop ?? 0
|
if (!useWindow) scrollY = virtualListEl?.scrollTop ?? 0
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
{#if !useGpu}
|
||||||
style="height: {cumulativeItemHeights[visibleItems?.[0]?.index - 1] ||
|
<div
|
||||||
0}px; border: 0 !important;"
|
style="height: {cumulativeItemHeights[visibleItems?.[0]?.index - 1] ||
|
||||||
></div>
|
0}px; border: 0 !important;"
|
||||||
|
></div>
|
||||||
|
{/if}
|
||||||
{#each visibleItems as item (item.index)}
|
{#each visibleItems as item (item.index)}
|
||||||
<div
|
<div
|
||||||
data-index={item.index}
|
data-index={item.index}
|
||||||
class="post-container fix-divide group/virtual"
|
class={[
|
||||||
|
'post-container fix-divide group/virtual w-full',
|
||||||
|
useGpu && 'absolute',
|
||||||
|
]}
|
||||||
|
style="{useGpu
|
||||||
|
? `transform: translateY(${item.offset}px);`
|
||||||
|
: ''} will-change: transform;"
|
||||||
use:resizeObserver
|
use:resizeObserver
|
||||||
>
|
>
|
||||||
{@render itemSnippet(item.index)}
|
{@render itemSnippet(item.index)}
|
||||||
|
|||||||
Reference in new issue
Block a user