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

Listen to scroll on another container #13

Open
MrUltimate opened this issue Nov 13, 2021 · 1 comment
Open

Listen to scroll on another container #13

MrUltimate opened this issue Nov 13, 2021 · 1 comment

Comments

@MrUltimate
Copy link

Hello!

By default, react-curtains listens to the window scroll for animating the curtains. This unfortunately doesn't work in some cases where you're scrolling a different container. Is there an easy way to listen to the scroll of another container and use the useCurtainEvents("onScroll") hook?

Thanks!

@martinlaxenaire
Copy link
Owner

Hi @MrUltimate,

Of course you can update the scroll values manually if you want.

First you should disable the watchScroll property of your <Curtains /> component:

<Curtains
    watchScroll={false}
    // ... your other options
>
    <App />
</Curtains>

Then, wherever your scrollable container lies, you should be able to do something like that:

useCurtains((curtains) => {
    const onScroll = () => {
      // assuming it's a vertical scroll
      const scrollValue = container.current.scrollTop;
      curtains.updateScrollValues(0, scrollValue);
    };
    
    container.current.addEventListener('scroll', onScroll);
    
    return () => container.current.removeEventListener('scroll', onScroll);
  });

This is untested but should work fine.

Cheers,

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