Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Code in items slow down page scrolling #56

Open
Amerlander opened this issue Oct 8, 2021 · 0 comments
Open

JS Code in items slow down page scrolling #56

Amerlander opened this issue Oct 8, 2021 · 0 comments

Comments

@Amerlander
Copy link

Amerlander commented Oct 8, 2021

Having list items with heavy js usage on initialization will lead to a buggy scroll experience.

As example I had a VirtualList with 8 columns and each item was using some jquery code to call a function from semantic ui:
window.$(cardItem).children('.inlinepopup').popup();

The popup was called when the item got initialized the first time, but when I scrolled down and up it doesnt. Therefore I wrapped it in a onMount function. That lead to a very laggy scroll experience.

I worked arround this by introducing a finished variable, which tells if the user is still scrolling or has finished/paused for at least 800ms:

VirtualList.svelte

export let finished = true;
let lastUpdate = Date.now();

async function handle_scroll() {
		finished = false;
// … whole existing handle_scroll() function here
		lastUpdate = Date.now();
}

$: {
        if(!finished && (lastUpdate + 800) < Date.now() ) {
            finished = true;
        } else if(!finished) {
            setTimeout(() => {
                lastUpdate = lastUpdate - 1
            }, 900);
        }
}

App.svelte

<VirtualList {items} let:item bind:finished>
	<ListItem  {item} {finished} />
</VirtualList>

ListItem.svelte

    export let finished;
    let initialized = false;

    $: {
        if(!initialized && finished ) {
            window.$(cardItem).children('.inlinepopup').popup();
            initialized = true;
        }
    }

If this is a good idea, I could open an PR.
Edit: maybe finished should be isScrolling instead with inverse boolean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant