-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from inokawa/vue-scroll-ref
Add scrollRef prop to Vue Virtualizer
- Loading branch information
Showing
4 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import { Virtualizer } from '../../src/vue' | ||
const sizes = [20, 40, 180, 77]; | ||
const createItem = (i: number) => ({ index: i, size: sizes[i % 4] + 'px' }) | ||
const data = Array.from({ length: 1000 }).map((_, i) => createItem(i)); | ||
const outerPadding = 40; | ||
const innerPadding = 60; | ||
const scrollRef = ref<HTMLElement>(); | ||
</script> | ||
|
||
<template> | ||
<div ref="scrollRef" :style="{ | ||
width: '100%', | ||
height: '100vh', | ||
overflowY: 'auto', | ||
// opt out browser's scroll anchoring on header/footer because it will conflict to scroll anchoring of virtualizer | ||
overflowAnchor: 'none' | ||
}"> | ||
<div :style="{ backgroundColor: 'burlywood', padding: outerPadding + 'px' }"> | ||
<div :style="{ backgroundColor: 'steelblue', padding: innerPadding + 'px' }"> | ||
<Virtualizer :data="data" #default="item" :scrollRef="scrollRef" :startMargin="outerPadding + innerPadding"> | ||
<div :key="item.index" :style="{ height: item.size, background: 'white', borderBottom: 'solid 1px #ccc' }"> | ||
{{ item.index }} | ||
</div> | ||
</Virtualizer> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
/* NOP */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters