I'm using Akryum/vue-virtual-scroller plugin on different tabs, how can i force vue-virtual-scroll to start from a specific scroll position programatically ?
How to start from a specific scroll position when using vue js vue-virtual-scroller plugin?
2.7k Views Asked by stackov At
3
There are 3 best solutions below
1
On
You can use the offset or start property : https://github.com/tangbc/vue-virtual-scroll-list#props-type
0
On
Use getListenerTarget()
Assuming you are talking about Akryum/vue-virtual-scroller
scrollToPosition and scrollToItem did not work for me so here's an alternative.
Us the getListenerTarget() method to get the dom element and then scroll using the native scrollTop method.
export default {
methods: {
scrollIt() {
let scroller = this.$refs.virtualScroller.getListenerTarget()
scroller.scrollTop = 200
}
}
}
<!-- Options have been left out for brevity -->
<RecycleScroller ref="virtualScroller">
<!-- ... -->
</RecycleScroller>
I found 2 methods
scrollToPositionandscrollToItem(not mentioned in the document) which is probably what you are looking for.You can use
scrollToItemon bothRecycleScrollerandDynamicScrollercomponents.For
scrollToPositioncan only use onRecycleScrollerbut you can getRecycleScrollercomponent by$refand use it anyway.Example