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

once not working #91

Open
thisispete opened this issue Nov 14, 2024 · 2 comments
Open

once not working #91

thisispete opened this issue Nov 14, 2024 · 2 comments

Comments

@thisispete
Copy link

thisispete commented Nov 14, 2024

when I use once and on:intersect the function seems to be getting called every frame instead of just one time.

  const doOnce = () => {
    console.log('once?');
    //this is firing every frame
  };
  
  ...
  
  <IntersectionObserver once {element} on:intersect={doOnce}>
  <div bind:this={element}>
  
  ...
Screenshot 2024-11-14 at 11 35 09
@thisispete
Copy link
Author

thisispete commented Nov 14, 2024

oh.. ok something just noticed: it fires every time the contents changes - so I have a tweened element inside, it fires every frame until the animation ends, and then it stops firing.

ie:

  const number = tweened(0, {
    duration: 5000
  });
  
  const doOnce = () => {
    console.log('once?');
    $number = 15000
  }
<IntersectionObserver once {element} on:intersect={doOnce}>
<div bind:this={element}>
  {$number}

this also messes with the duration of the tween - as a side effect, it's resetting every frame, so it takes much longer the bigger the number or the more decimal places.

@metonym
Copy link
Owner

metonym commented Nov 14, 2024

Could you provide a minimal repro? https://svelte.dev/playground/hello-world?version=5.2.0

Is this using Svelte 5? Happy to help debug.

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

2 participants