Building a Spendee-style scroll theme switch on a Next.js landing page

Building a Spendee-style scroll theme switch on a Next.js landing page

How Costility's desktop hero pins, grows a dark circle out of the phone mock, and swaps the light expenses pitch for the dark utilities scene as you scroll — without fighting mobile or reduced motion.

By Cristian Muscalu ·

What we're going for

Spendee-style marketing pages do a trick that looks expensive: the hero stays pinned while a dark theme blooms out of the product shot, and the left-side copy changes mid-scroll. On Costility we wanted that on desktop only — phones keep a normal short hero.

The stack is boring on purpose: sticky layout + CSS variables + one requestAnimationFrame scroll listener. No scroll library.

scroll-theme-hero-preview.gif-img

1. Give the hero room to pin

Make the section taller than the viewport so sticky has travel. The inner pin is position: sticky; top: 0; height: 100vh. Everything "magical" happens while that pin stays locked and the tall section scrolls underneath.

Gate the whole effect on min-width: 1024px and prefers-reduced-motion: no-preference. Below that breakpoint the CSS never applies, so mobile never inherits a 190vh trap.

globals.css

2. Two scenes, one clip-path circle

Light copy and phones sit in the pin. A second layer (.theme-hero__veil) holds the dark headline, store links, and desktop browser mock. That veil starts invisible and is revealed with a growing clip-path: circle(...) centered on the front phone.

  • --rx / --ry — phone center inside the pin
  • --r0 — starting hole (roughly half the phone width)
  • --R — radius that reaches every corner of the pin
  • --g — eased progress 0→1 that grows the circle
  • --a — light-copy opacity / lift so expenses fade as utilities arrive
globals.css

3. Drive CSS vars from scroll

On each frame we measure the tall hero's travel, map it to progress, ease the reveal, and write variables onto the hero node. When reveal is nearly done we set data-hero-dark on the landing root so the navbar can flip with the scene.

Throttle with rAF, listen passive, and re-run on resize + media-query change. If the user rotates into desktop width mid-session, the effect arms itself without a reload.

landing-page.tsx

4. Crossfade the story, not just the paint

Light copy uses opacity: var(--a) and a slight upward translate. Dark copy and the browser mock fade in from mid-progress with CSS calc thresholds so the second headline appears roughly where the first one lived. CTAs on the light side hide once dimmed; dark-side store/web links become visible then.

globals.css

Tradeoffs we accepted

  • Desktop only. The bloom needs horizontal space and a tall scroll budget. On small screens a normal stacked hero reads better.
  • Motion preference wins. Reduced motion users get the dark page without the circle choreography.
  • Measuring the phone every frame. Cheap enough with rAF; keeps the origin locked when the sticky pin and responsive phone size shift.
  • Navbar theme coupling. data-hero-dark + :has() lets chrome flip with the veil instead of a second scroll listener.

Checklist if you steal this

  • Tall section + sticky pin only inside a desktop + motion media query
  • Second scene as an absolute veil, clipped by a circle at the product center
  • One scroll driver writing --g / --a / --rx / --ry / --r0 / --R
  • Clear all of that when the media query stops matching
  • Use the dark flag for shared chrome (nav, banners), not a second animation system

Live reference: the Costility marketing hero on desktop.