Skip to content

[FEATURE] ScrollObserver - Play immediately if target is already within the container #1007

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

Open
joelearn opened this issue Apr 30, 2025 · 0 comments

Comments

@joelearn
Copy link

In some cases, we need a scroll observer to trigger an animation on page load if the target element is already within its container. This can occur, for example, when the user reloads the page after scrolling down and the browser retains the scroll position.

This is my current solution, which I admit is a little bit hacky:

const anim = animate('.target', {
  opacity: [0, 1],
  autoplay: onScroll({
    onEnter: (e) => {
      setTimeout(() => {
        if (e.isInView) anim.play()
      })
    }
  })
})

It would be great to have an option to enable this, perhaps something like:

const anim = animate('.target', {
  opacity: [0, 1],
  autoplay: onScroll({ playIfInViewOnLoad: true })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant