Using react-visibility-sensor I've created a higher component to animate the sections of my project on scroll.
I'm having problems trying to make it work only on the first scroll. At the moment the sections appear and disappear.
Any help would be really appreciated. Cheers!
import VisibilitySensor from 'react-visibility-sensor';
export const SlideUp = ({ children }) => {
const [isVisible, setVisibility] = useState(false);
const onChange = visiblity => {
setVisibility(visiblity);
};
return (
<VisibilitySensor
partialVisibility
offset={{ top: 200 }}
onChange={onChange}
>
<div
style={{
transition: `opacity ${0.5}s ease, transform ${0.5}s ease`,
opacity: isVisible ? 1 : 0,
transform: isVisible ? `translateY(${0}px)` : `translateY(${20}px)`,
}}
>
{children}
</div>
</VisibilitySensor>
);
};```
- use example:
<SlideUp>
<Section />
</SlideUp>