Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent Reversing of Animation? #166

Unanswered
kirill-develops asked this question in Q&A
Discussion options

Hi there, playing around with the package. Pretty intuitive, thanks for building it!

Is there a way that once the animation is complete, it no longer reverses when scrolling in the opposite way? I noticed the onExit() callback prop but, I'm not sure how to instruct it to go into a 'completed' state

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

On exit won't work in this case since it could exit the top of the viewport and not have completed the full animation.

Instead, you can track the progress of that animation, then once it's completed set local state to disable the parallax effect. Not the most elegant solution but it may work for your use case.

function Example() {
 const [isComplete, setIscomplete] = useState(false);
 const parallax = useParallax<HTMLDivElement>({
 scale: [0, 1],
 disabled: isComplete,
 onProgressChange: (x: number) => {
 if (x >= 1) {
 setIscomplete(true);
 }
 }
 });
 return (
 <div className={`test ${isComplete ? " done" : ""}`} ref={parallax.ref}>
 Test
 </div>
 );
}

https://codesandbox.io/s/react-scroll-parallax-disable-after-complete-i18mjm?file=/src/Example.tsx

You must be logged in to vote
1 reply
Comment options

Thank you, that will work for now!

Would be a cool feature for the future ;) Great Package, mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /