Scroll-Triggered Animations
Animate elements as they enter view.
Animating on Scroll
A popular effect is fading or sliding elements into view as the user scrolls to them. Intersection Observer makes this clean: add a CSS class when an element enters the viewport, and let CSS handle the animation.
The CSS Side
Define a hidden starting state and a visible end state in CSS. The JavaScript only toggles a class; the transition is pure CSS, which keeps it smooth.
// .reveal { opacity: 0; transform: translateY(20px);
// transition: opacity 0.6s, transform 0.6s; }
// .reveal.visible { opacity: 1; transform: none; }All lessons in this course
- Observing Element Visibility
- Lazy Loading Images
- Infinite Scrolling
- Scroll-Triggered Animations