brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: animation-timeline: view() in CSS fades cards in as they scroll into view

Css
~/tips/tip-css-animation-timeline-view-reveal

animation-timeline: view();

A scroll-driven animation replaces the IntersectionObserver code for simple reveal effects.

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

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link