anime icon indicating copy to clipboard operation
anime copied to clipboard

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

Open joelearn opened this issue 8 months ago • 0 comments

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 })
})

joelearn avatar Apr 30 '25 11:04 joelearn