whileInView: Animate an element entering the viewport

Unlock this video and the rest of this course by joining Frontend.FYI PRO .

The first type of scroll animations are called “scroll-triggered” animations: animations that are triggered when en element enters or leaves the viewport. They don’t change over time based on how far the user has scrolled, but trigger at a certain point.

What they could look like

The four blocks below are set to animate when they enter the viewport. Each item animates in with a small delay after the other (we use staggerChildren for this!). As soon as the elements get out of view again, they animate out.

Scroll down a bit until this element gets out of view, and notice the blocks disappear.

Unlock the full lesson with PRO

Want to read the full lesson? Join Frontend.FYI PRO.

PRO is a one time purchase of €149 that gives you lifetime access to this course, any courses released in the future, and so much more!