Getting the scroll position of Parallax #1333
Replies: 11 comments 3 replies
-
Please add example code of the API you're expecting, if you can. Thanks 👍 |
Beta Was this translation helpful? Give feedback.
-
+1 |
Beta Was this translation helpful? Give feedback.
-
Ended up implementing a |
Beta Was this translation helpful? Give feedback.
-
sorry can you help me with a little example, currently my code is similar to this but it doesn't work
|
Beta Was this translation helpful? Give feedback.
-
That's how I implemented the hook (the timeout is just playing with delay). You might want to keep the |
Beta Was this translation helpful? Give feedback.
-
Thx @michaelwachell. |
Beta Was this translation helpful? Give feedback.
-
@michaelwachell's code is great for determining onScreen, but I'd still love to get the actual scroll position. (I had some UI logic built around window.pageYOffset, and I'm trying to drop in react-spring parallax without breaking.) Any help appreciated. |
Beta Was this translation helpful? Give feedback.
-
I want to implement a feature that if I scroll down the page -> the nav bar hides and scroll up -> the nav bar shows up again. And I need to know |
Beta Was this translation helpful? Give feedback.
-
It isn't documented (because it's only used internally) but you can get the current scroll position using a The issue is that A sort of hacky way around it is giving ...
const parallax = useRef();
const handleScroll = () => {
if (parallax.current) {
console.log(parallax.current.current)
}
}
useEffect(() => {
const container = document.querySelector('.my-class-name')
container.addEventListener('scroll', handleScroll)
return () => {
container.removeEventListener('scroll', handleScroll)
}
}, [])
return (
<Parallax ref={parallax} className='my-class-name'>
... -- Obligatory warning that it is internal and therefore subject to change. -- |
Beta Was this translation helpful? Give feedback.
-
adding a an event listener scroll to window is pointless because the Parallax element scrolls and not the window itself. Therefore console logging window's scroll position doesn't work and so I was wondering how I am to get the scroll position within parallax so that I could add a few spring animations on scroll within parallax.
Beta Was this translation helpful? Give feedback.
All reactions