James Hudson
James Hudson

Reputation: 904

vuetify & v-virtual-scroll : how can I programmatically scroll an item into view?

I know what my item height is and I know the position of the item in the list, so I should be able to calculate the scroll position. However, I am not sure how to set the scroll position.

Upvotes: 4

Views: 3377

Answers (2)

maki000
maki000

Reputation: 339

With Vuetify 2 you can use this.$vuetify.goTo($target, $options) where $target is html element query e.g. '#targetElementId' or HTMLElement object, while all available $options you can find here.

In Vuetify 3, you can use scrollToIndex().

Upvotes: 2

EricL
EricL

Reputation: 29

For v-virtual-scroll, you can set the scrollTop to scroll an item into view.

You can assign an id to your v-virtual-scroll element for easy selection, then set the scrollTop, like this:

let itemHeight = 48, itemIndex = 10; // set as appropriate
document.getElementById("my-scroller").scrollTop = itemHeight * itemIndex;

Upvotes: 1

Related Questions