Skip to content

Commit fe72c43

Browse files
authored
fix: Account for the height of the leading and trailing slots when calculating visible items, fix #685 (#754)
1 parent a6e07da commit fe72c43

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/demo/src/components/DynamicScrollerDemo.vue

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

packages/vue-virtual-scroller/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"
@@ -321,6 +323,18 @@ export default {
321323
scroll.start -= buffer
322324
scroll.end += buffer
323325
326+
// account for leading slot
327+
if (this.$refs.before){
328+
const lead = this.$refs.before.scrollHeight;
329+
scroll.start -= lead;
330+
}
331+
332+
// account for trailing slot
333+
if (this.$refs.after){
334+
const trail = this.$refs.after.scrollHeight;
335+
scroll.end += trail;
336+
}
337+
324338
// Variable size mode
325339
if (itemSize === null) {
326340
let h

0 commit comments

Comments
 (0)