Skip to content

Commit d3fb697

Browse files
committed
improve scrollTo consistency
1 parent 5d73394 commit d3fb697

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/VirtualScroller.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
defineComponent, ref, PropType, VNode, toRefs, computed, CSSProperties,
2+
defineComponent, ref, PropType, VNode, toRefs, computed, CSSProperties, nextTick,
33
} from 'vue';
4-
import { useElementSize } from '@vueuse/core';
4+
import { useElementSize, watchOnce } from '@vueuse/core';
55
import { useDynamicSizeScroller } from './dynamic-scroller';
66
import { ItemContext } from './types';
77
import { useScrollDirection } from './scroll-direction';
@@ -70,6 +70,10 @@ export function createVirtualScroller<T>() {
7070
}
7171

7272
container.value.scrollTop = position;
73+
74+
watchOnce(scroller.offsets, () => {
75+
nextTick(() => { container.value!.scrollTop = scroller.getOffset(index)!; });
76+
});
7377
};
7478

7579
expose({

src/dynamic-scroller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function useDynamicSizeScroller<T>(args: DyanmicSizeScrollerArgs<T>) {
9999
});
100100

101101
return {
102+
offsets,
102103
getOffset,
103104
measure,
104105
visibleItems,

0 commit comments

Comments
 (0)