I’ll show you how to create animations when scrolling our page.
Hello there!
Finally I can share with you another post about react & gsap. As promised in the previous part - here, I’ll show you how to create animations when scrolling our page.
Let’s get started.
First, create new project by typing: 'npx create-react-app project-name'
After all dependencies are installed and created, we can download gsap library. To do that, we need to open terminal with project location and type: 'npm install gsap'
At the 1st step let’s clear the code from default things.
In App.js delete all html elements except highest div
Now, we can use the ‘useEffect’ and ‘useRef’ hooks to make initial refs for our components. And of course, the names of variables or styling is up to you :).
Import React, { useRef, useEffect } from ‘react’;
…
const App = () => {
const titleRef = useRef(null);
useEffect(() => {
// here will be our animation
}, []);
return (
<div className="App">
<p ref={titleRef}> You can animate everything!</p>
</div>
);
}
After that, lets change our App.css to prepare some better styling and to make the scroll appear: