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

Is it possible to add laxxx effects to elements inside of a fixed div with 'overflow: scroll'? #73

Closed
rchrdnsh opened this issue Dec 3, 2019 · 3 comments

Comments

@rchrdnsh
Copy link

rchrdnsh commented Dec 3, 2019

I see that this uses the windows scroll position, but would it be possible to add laxxx effects to the elements inside of a div that is fixed, but has overflow-y: scroll?

also curious how that might be implemented using the react hooks version as well :-)

I might have missed it in the docs, if so, my apologies :-)

@alexfoxy
Copy link
Owner

alexfoxy commented Dec 3, 2019

Yes this is possible. Check my answer to: #66 #66

@alexfoxy alexfoxy closed this as completed Dec 3, 2019
@rchrdnsh
Copy link
Author

rchrdnsh commented Dec 3, 2019

yup, totally did not see that one, thank you :-)

@rchrdnsh
Copy link
Author

rchrdnsh commented Dec 3, 2019

sweet, it worked!

I just made my own hook, ala useLax, like so, directly in the component I'm parallaxing in:

function useLax() {
  const requestRef = useRef();

  useEffect(() => {
    lax.setup() // initialization
    const element = document.querySelector('#scroller') // Find your scrollable element

    const updateLax = () => {
      lax.update(element.scrollTop) // pass in the elements scrolled position
      requestRef.current = window.requestAnimationFrame(updateLax);
    };

    requestRef.current = window.requestAnimationFrame(updateLax);

    return () => {
      if (requestRef.current) {
        window.cancelAnimationFrame(requestRef.current);
      }
    };
  }, []);
}

Thank you for this library! XD

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