patrick_jones88
New Member
- Messages
- 60
- Reaction score
- 0
- Location
- Glasgow, UK
Spent last week ripping the scroll-reveal code out of a marketing site I maintain. It was the usual pile: one IntersectionObserver, threshold: 0.15, a class toggle, a CSS transition, and a handful of unobserve calls I kept forgetting to add. Worked fine. But every new section meant touching JS again.
Now it's this:
@keyframes reveal {
from { opacity: 0; translate: 0 24px; }
to { opacity: 1; translate: 0 0; }
}
.reveal {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 10% cover 35%;
}
That's the whole thing. No observers, no cleanup, no scroll listeners fighting the compositor for main thread time. On my Pixel 4a the old version was dropping frames during fast flicks, this one is glassy. Bonus: it also killed a bug where the observer fired for elements inside a transformed parent and revealed half the page at once.
The catch, obviously, is support. Chrome and Edge have had it for a while, Firefox shipped it recently, Safari is still behind a flag last I checked. So I wrapped everything in @supports (animation-timeline: view()) and left the observer path as the fallback. Which means I'm maintaining both for another year and haven't actually deleted any JS. Cool.
Other stuff I ran into:
- No events. If you need to flip state on something else (nav, a counter, analytics), you're back to IntersectionObserver. This is purely visual.
prefers-reduced-motionis on you, there's no free opt-out. I put the whole block inside@media (prefers-reduced-motion: no-preference).- Named timelines (
scroll-timeline-nameplustimeline-scope) are where it gets genuinely powerful and also where I broke my layout twice. Elements in aposition: fixedsubtree don't see the document scroller, which took me an embarrassing amount of time to work out. animation-rangepercentages are far less intuitive than they look. I ended up dragging the numbers around until it felt right, which is not a great workflow.
Nicest part is that designers can nudge animation-range in devtools and see it live, so I'm not the bottleneck on every "can it fade in a bit later" request anymore.
Anyone shipped this on something real? Curious whether you kept the fallback path or just let old Safari eat a static page.