swapped IntersectionObserver for animation-timeline and I'm never going back

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-motion is on you, there's no free opt-out. I put the whole block inside @media (prefers-reduced-motion: no-preference).
  • Named timelines (scroll-timeline-name plus timeline-scope) are where it gets genuinely powerful and also where I broke my layout twice. Elements in a position: fixed subtree don't see the document scroller, which took me an embarrassing amount of time to work out.
  • animation-range percentages 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.

w0lfpack88

New Member
Messages
72
Reaction score
0
Location
Oslo, NO

Kept the fallback, and I'd keep it way past a year if your traffic skews old.

Not being dramatic. I run a couple of casino comparison sites and iOS Safari on iPad is close to a fifth of sessions, and those are the ones actually clicking through and depositing. Letting them eat a static page is leaving money on the table. None of them are updating to whatever Safari build unlocks this anyway, they're on an iPad from 2019 that still works fine.

The INP win is real though. I had three scroll listeners stacked on the homepage (sticky nav, a lazy counter, one for a promo banner) and ripping them out for the view() timeline got my INP from like 180ms to well under 100. Mobile only, desktop was always fine. Same as you the observers were firing on stuff inside transformed parents, I had a whole modal revealing sections behind it.

Your animation-range point is the bit that worries me. "Drag the numbers until it feels right" works when it's you doing it, less so when a designer pushes a tweak at 4pm Friday and nobody remembers why the range is entry 12% cover 38%. Did you end up standardising a couple of named ranges so it's not bespoke per section? That's the thing stopping me from rolling it out everywhere.

kewldad

New Member
Messages
60
Reaction score
0
Location
Calgary, AB

Honestly I went the other way and just killed the fallback on one project. Not brave, just lazy, and the numbers were small enough that I could eat it. But your point about iPad Safari on the deposit pages is the kind of thing that would've bitten me six months later, so maybe I got lucky rather than smart.

On the ranges, yeah I ended up with like four named ones and it's the only thing that made it maintainable. Something like --reveal-tight, --reveal-loose, --reveal-hero, and a --reveal-none for reduced motion. Designers pick from a dropdown in the CMS, I never touch the raw percentages again. The bespoke per-section stuff is exactly what killed the last animation system we had, nobody could remember why anything was what it was.

Curious what your INP numbers look like after a few weeks though. Mine crept back up a bit once the marketing team stuffed a video embed in the hero, so the scroll win was real but not permanent.

w0lfpack88

New Member
Messages
72
Reaction score
0
Location
Oslo, NO

Four named ranges is more discipline than I've managed. I got as far as a comment block at the top of the stylesheet documenting mine, which survived until roughly the second redesign.

The CMS dropdown part is what I can't get to. My sites are WordPress with a page builder bolted on, so "designers pick from a dropdown" means someone has to build the dropdown first, and that someone is me, at 11pm. So right now it's a pile of utility classes and hope. Tbh the bespoke range thing hasn't bitten me yet but I can feel it coming.

And yeah, my INP crept back too. Not a video, a comparison table with like 40 operator logos, all lazy loaded, and I was back up around 140ms. Turned out it wasn't the reveal at all, it was images with no width and height so the layout was shifting under the animation. Fixed the dimensions and it settled. So the scroll win is real but it's a floor, not a ceiling. Anything that touches layout eats it right back.

What'd you do with the video, facade it or just move it out of the hero entirely? I've got a promo section I keep threatening to gut.

rk_designs

New Member
Messages
68
Reaction score
0
Location
Vancouver, BC

w0lfpack88 the in-app browser angle is the one nobody's mentioning and it's the one that bites hardest on my traffic. Facebook and Instagram webviews on older Android report as Chrome so your @supports check is happy, but the compositor path is different and I've had reveals that just sit there at opacity 0. Not a fallback problem, an "is it even running" problem. Two users emailed me about the page looking broken before I worked it out. So I'd argue against kewldad's lazy approach for a different reason than the iPad one, it's not that old Safari eats a static page, it's that some browsers eat a blank page and you don't find out until someone complains.

On the ranges, four named ones sounds right but I can't get there either. My stack is the same WordPress plus page builder mess, so every "just add a dropdown" turns into me writing a custom block at 11pm and then someone reinstalls the theme and it's gone. What I've landed on is brutally simple: default range, one "slow" variant, and everything else is a hard no. Designer wants something bespoke, they can open the CSS themselves. Sounds harsh, works better than the comment block that w0lfpack88's second redesign ate.

Curious about the video though. Facade or gut it? I've got a hero video on one site that's killing me on mobile and I keep telling myself the autoplay loop converts, but I've never actually tested it against a static image. If you ripped it out and nothing moved, that's free performance and I'd do it tomorrow.

greg_ohio

New Member
Messages
71
Reaction score
0
Location
Columbus, OH

most of this is above my level ngl, but rk_designs the webview thing just gave me a headache I didn't know I had. I run a small slots affiliate site (WordPress + Elementor, same mess w0lfpack88 described) and I had reveals sitting at opacity 0 on some Androids, I honestly thought my host was just slow lol.

Question bhai, how do you even test for that? I can't ask my users to open devtools inside the Facebook browser. Do you keep a couple of old phones lying around or is there a cheaper way?

And yeah the @supports saying true while the thing doesn't actually run is the scary part. Makes me want to just copy the OP's code, wrap it, and never touch it again, which is probably exactly how the next bug gets born.

bananapeel42

New Member
Messages
53
Reaction score
0
Location
Manchester, UK

rk_designs I think you're blaming the wrong patient. You've got the observer fallback in place and the reveals still sit at opacity 0 in those webviews, yeah? Then the CSS timeline isn't what failed. The fallback failed. Which means the real bug is that your elements start invisible and sit there waiting for something, anything, to switch them on. That's fragile no matter which engine is running underneath. The webview just happens to be where the waiter didn't show up.

Which leads into the thing I'll get yelled at for: I don't think you need the fallback at all. Look at the OP's declaration again. animation: reveal linear both; with no duration. Duration defaults to 0s. In a browser that doesn't understand animation-timeline, that declaration is dropped, the animation runs on the document timeline, and it finishes instantly at t=0. With both fill, the end state sticks. Element is visible. The graceful degradation is free. The @supports wrapper and the observer path are you maintaining two systems to solve a problem the default already solved. I shipped the wrapper everywhere for about eight months because it felt responsible, then deleted the whole observer file on a project and nothing moved.

Caveat, and it's a real one: the second you set an explicit animation-duration on those rules, this stops being true and unsupporting browsers get a slow time-based fade on load instead. So that becomes a rule you have to enforce, which is its own kind of tax.

greg_ohio on testing, cheap version is a $40 used Android off Marketplace that you keep in a drawer and open the Facebook browser on. BrowserStack does real device cloud too but you're paying monthly for something you'll use twice. Devtools device emulation will not reproduce it, that's the trap, it emulates the viewport and the UA string, not the compositor. And honestly the fastest sanity check is a query flag like ?nofx=1 that strips the animation block entirely. If the page looks fine with it stripped, you've already got your answer and you didn't need the phone.

rk_designs, did you ever get

You must log in or register to reply here.