So I've only been working a couple of months in ReactJS, so please excuse me if the solution is simple.
I'm using the intersection observer from react-use to trigger a gsap animation once the desired section is in viewport. Now I don't want it to animate out, only animate in (once on initial load). I follow a tutorial, but their explanation was only to comment out the fade out animation, which is not working for me.
My code looks something like this:
const App = () =>{
const sectionRef = useRef(null);
const headlineFirst = ".animate-this-div"
const intersection = useIntersection(sectionRef, {root: null,rootMargin:
"0px",threshold: 0.4});
const fadeIn = () => {gsap.to(headlineFirst, 1, {opacity: 1,y:11,})};
const fadeOut = () => {
// gsap.to(headlineFirst , 1, {
// opacity: 1,
// y:49,
// })
};
intersection && intersection.intersectionRatio < 0.4
? fadeOut()
: fadeIn(headlineFirst);
return (
<div ref={ sectionRef } className="some-div">
<div className="animate-this-div"></div>
</div>
It must probably be the ternary operator. Would an "if statement" work instead, how would that "if statement" look (sorry still a noob at ReactJS)? Any advise would be SUPER appreciated