svelte-virtual-list icon indicating copy to clipboard operation
svelte-virtual-list copied to clipboard

How to scroll to invisible element in the list?

Open rsousacode opened this issue 4 years ago • 2 comments

How to scroll to invisible element in the list?

Using svelte "this binding" is not possible since the HTML element is null while invisible.

rsousacode avatar Dec 19 '20 11:12 rsousacode

I got a very hacky solution (a boolean flag) to make it work with no apparent scrolling bugs with the help of _scrollTo3 provided here: https://github.com/sveltejs/svelte-virtual-list/issues/43.

This basically de-virtualize the list, but at least the load time of the page is still ok.

let handle = true

async function _scrollTo3 (index, opts) {
    // code 

    handle = false

}


async function handle_scroll(event) {
    // ...

    end = i;
    
    if(!handle) return // add this here

    const remaining = items.length - end;
    
    // ...

}

rsousacode avatar Dec 19 '20 21:12 rsousacode

I think in the mean time I've removed the _scrollTo3 function in favour for a clean PullRequest, which introduces now the function scrollToIndex. Maybe you like to check out the demo again and see, if the second column fits to your use-case, if you replace the random index with a specific one in App.svelte ln.22 like randomIndex = 100

https://svelte.dev/repl/1c36db7c1e7e4ef2bfb04874321412e5?version=3.20.1

gitbreaker222 avatar Apr 11 '21 10:04 gitbreaker222