Closed asjustis closed 1 year ago
Update: I was able to make it work by moving ParallaxProvider
to the Test
script and setting the scrollContainer
parameter manually. Not sure if that's a natural behaviour in this case though.
Sounds like the scroll container wasn't the expected default (document body) when it was used in _app
.
Got it, thanks. Seems for NextJS the easiest way to make it work is to set scrollContainer
manually for <ParallaxProvider scrollContainer={...}>
and if needed to pass the same element to children as in:
Parent component:
const [parallaxScrollEl, setParallaxEl] = useState(null);
const scrollRef = useRef(null);
useEffect(() => {
setParallaxEl(scrollRef.current);
}, [scrollRef]);
<ParallaxProvider
scrollAxis="horizontal"
scrollContainer={parallaxScrollEl}
>
<div ref={scrollRef}>
<CustomComponent parallaxEl={parallaxScrollEl} ... />
</div>
>
CustomComponent:
const CustomComponent = (props) => {
const { parallaxEl } = props;
return <ParallaxProvider scrollAxis="horizontal" scrollContainer={parallaxEl}>
<Parallax ...>{/* use parallax here in child component*/}</Parallax>
</ParallaxProvider>
}
Maybe this helps someone
Bug
HI guys. I am trying to make horizontal parallax effect on my NextJS, and I wonder if I am doing something wrong here, or is there something with the lib.
So this sandbox works as I expect it: https://codesandbox.io/s/hopeful-hill-hocwy3?file=/src/App.js
However, trying the same thing on my NextJS project, it simply adds initial offset and does not animate. Below is the code I use. Any insights?
_app.js
parallax.js