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

Execute functions based on scroll index #11

Open
jbixon13 opened this issue Sep 14, 2020 · 3 comments
Open

Execute functions based on scroll index #11

jbixon13 opened this issue Sep 14, 2020 · 3 comments

Comments

@jbixon13
Copy link

jbixon13 commented Sep 14, 2020

Is it possible to execute arbitrary functions such as:

<script>
	let index 

	function count() {
		console.log('this executes upon scrolling to the third section');
	}

	if (index = 2) {
		count()
	}
</script>

This is possible in something like scrollama.js, and I would like to use svelte-scroller to do so if possible as it's already built into Svelte.

@jtrim-ons
Copy link
Contributor

I think it should work if you do this:

$: if (index == 2) {
    count();
}

I've opened PR #14 to avoid repeated calls to the function (you could alternatively use another variable to keep track of whether index has changed from its previous value).

@maxgraze-zz
Copy link

Hello! I was wondering this too. I tried this as well but my function ended up getting called over 100 times and glitching.

@jtrim-ons
Copy link
Contributor

@maxgraze here is the version where I tried to fix the issue of repeated function calls: https://github.com/jtrim-ons/svelte-scroller/blob/fewer-section-updates/Scroller.svelte . If you decide to give it a try, let us know if it works.

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

3 participants