diff --git a/packages/vuetify/src/composables/virtual.ts b/packages/vuetify/src/composables/virtual.ts index d92b5a01678..4ec291bae6a 100644 --- a/packages/vuetify/src/composables/virtual.ts +++ b/packages/vuetify/src/composables/virtual.ts @@ -126,7 +126,12 @@ export function useVirtual (props: VirtualProps, items: Ref) { function calculateOffset (index: number) { index = clamp(index, 0, items.value.length - 1) - return offsets[index] || 0 + const whole = Math.floor(index) + const fraction = index % 1 + const next = whole + 1 + const wholeOffset = offsets[whole] || 0 + const nextOffset = offsets[next] ?? wholeOffset + return wholeOffset + (nextOffset - wholeOffset) * fraction } function calculateIndex (scrollTop: number) { @@ -220,12 +225,19 @@ export function useVirtual (props: VirtualProps, items: Ref) { paddingBottom.value = calculateOffset(items.value.length) - calculateOffset(last.value) } - function scrollToIndex (index: number) { + function scrollToIndex (index: number, options?: ScrollToOptions) { const offset = calculateOffset(index) if (!containerRef.value || (index && !offset)) { targetScrollIndex = index } else { - containerRef.value.scrollTop = offset + if (options) { + containerRef.value.scrollTo({ + top: offset, + ...options, + }) + } else { + containerRef.value.scrollTop = offset + } } }