Skip to content

Commit 24ab3ba

Browse files
danatcofoDaniel Gidman
andauthored
fix: Account for the height of the leading and trailing slots when calculating visible items, fix #685
Co-authored-by: Daniel Gidman <[email protected]>
1 parent 4d3b956 commit 24ab3ba

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs-src/src/components/DynamicScrollerDemo.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
The message heights are unknown.
1818
</div>
1919
</template>
20-
20+
<template #after>
21+
<div class="notice">
22+
You have reached the end.
23+
</div>
24+
</template>
2125
<template v-slot="{ item, index, active }">
2226
<DynamicScrollerItem
2327
:item="item"

src/components/RecycleScroller.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<div
1313
v-if="$slots.before"
1414
class="vue-recycle-scroller__slot"
15+
ref="before"
1516
>
1617
<slot
1718
name="before"
@@ -43,6 +44,7 @@
4344
<div
4445
v-if="$slots.after"
4546
class="vue-recycle-scroller__slot"
47+
ref="after"
4648
>
4749
<slot
4850
name="after"
@@ -316,6 +318,18 @@ export default {
316318
scroll.start -= buffer
317319
scroll.end += buffer
318320
321+
// account for leading slot
322+
if (this.$refs.before){
323+
const lead = this.$refs.before.scrollHeight;
324+
scroll.start -= lead;
325+
}
326+
327+
// account for trailing slot
328+
if (this.$refs.after){
329+
const trail = this.$refs.after.scrollHeight;
330+
scroll.end += trail;
331+
}
332+
319333
// Variable size mode
320334
if (itemSize === null) {
321335
let h

0 commit comments

Comments
 (0)