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

Feature Request: rootMargin currently only supports number and not percentage values #157

Open
dohomi opened this issue May 3, 2022 · 4 comments

Comments

@dohomi
Copy link
Contributor

dohomi commented May 3, 2022

I would love to trigger the scroll animation when the middle of a screen is passed (animated timeline with connector). This currently seems not be able because rootMargin is bind to top, left, bottom, right and all values seems to be number (pixel) only.

Do you have a solution to start the scroll animation in the middle of the viewport?

@jscottsmith
Copy link
Owner

Ya, I'll have to think about this some more because I'm not sure rootMargin is the right API to adapt for this. Currently it works by adding a margin around an element so that it appears to enter earlier or leave later. In your case the percent would be based off the view (scroll window). If we did go this route, you'd need to do something like rootMargin: [-50%, 0, 0, 0]. This feels odd.

Maybe a new configuration option should be created. Something like viewportSize that would effectively scale the scroll view to the area where you want to animate. In your case viewportSize: [0 0, 50%, 0] -- 50% from the bottom of the view, begin the scroll animation.

In the meantime you may want to just use a targetElement. Here's a not so perfect example but may help https://codesandbox.io/s/react-scroll-parallax-start-at-center-5r1vsw?file=/src/styles.css

@dohomi
Copy link
Contributor Author

dohomi commented May 4, 2022

@jscottsmith thanks for your explanation. I am currently unsure if this package actually is the right one to have this timeline effect as shown in for example in this demo:
https://codesandbox.io/s/brave-kepler-fdbzv?file=/src/App.js:0-1097
as I use already the react-scroll-parallax I thought I could reduce some bundle size but wasn't yet successful

@jscottsmith
Copy link
Owner

I see. Ya you may be able to achieve that but it could be a little tricky. I tried mocking something up using startScroll and endScroll which you'd have to calculate manually to fit your needs:

https://codesandbox.io/s/react-scroll-parallax-view-progress-0h7r00?file=/src/App.tsx

But you may be better off with just another package ;)

@dohomi
Copy link
Contributor Author

dohomi commented May 9, 2022

Thanks for the demo :-)

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

2 participants