For a simple fade in on scroll I wouldn’t reach for an observer script anymore. CSS can tie an animation to how far an element has scrolled into the viewport.
@keyframes reveal {
from { opacity: 0; translate: 0 2rem; }
to { opacity: 1; translate: 0 0; }
}
.card {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% cover 30%;
}
With view() the progress of the animation follows the element’s position in the scrollport instead of the clock. animation-range sets when it starts and ends: here from the moment the card begins to enter until it covers 30 percent of the range. Scroll back up and it runs in reverse.
Order matters. The animation shorthand resets animation-timeline, so put the timeline after the shorthand or it is gone.
Chrome has had it since 115 and Safari since 26, and Firefox only shipped it in version 159. Wrap the rules in @supports (animation-timeline: view()) so older browsers show the cards normally instead of stuck at opacity 0, and switch it off for people who prefer reduced motion.
Further reading: MDN: animation-timeline, MDN: animation-range