Rebuilding Apple's Vision Pro scroll animation without JavaScript

Apple's scrolly teardowns remain a high bar for product pages, but they lean on JavaScript and are not always responsive — at certain widths Apple swaps in a static image. The Vision Pro sequence, found on the black background a little more than halfway down the product site, offers a test case: can the same effect be rebuilt in CSS alone and made responsive? It can, though the CSS-only version, at the time of writing, will not work in Firefox.

The original breaks into two movements. In the first, three electronic components rise in sequence out of the Vision Pro at the bottom of the page. Each component is a pair of images, placed both in front of and behind its neighbors — the outer pair spanning the full depth, the next wrapping the innermost — so that transparent regions let the images behind show through and the stack reads as 3D. The second movement flips the device up to reveal the eyepieces; Apple achieves this with a video whose playback is advanced by JavaScript as the user scrolls.

Staging the exploding hardware

Apple's six component images can be borrowed directly. A first attempt used a stack of img tags in a div with position: fixed to pin them and position: absolute to overlap them, which produced two failures: shrinking the viewport pushed the images off screen, and the Vision Pro could no longer scroll into and out of view as it does on Apple's site.

Apple's own construction pointed the way — each image as a background at background-position: bottom center with background-size: cover to hold a consistent aspect ratio. Overlap was still needed without the out-of-flow behavior of absolute positioning, so the parent gets display: grid and every image is assigned to the same grid area.

.visionpro { /* the overarching div that holds all the images */
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
.part { /* each of the images has a part class */
  grid-area: 1 / 1 / 2 / 2;
}

For the timeline, a scroll timeline pinned to the whole html element was the starting point, but since the Vision Pro needs to scroll both into and out of the viewport, a view timeline is the better fit: the animation starts when the element enters view instead of relying on a keyframe percentage estimated from the element's position — brittle and non-responsive.

Holding the device on screen while it animates, then releasing it, is a textbook case for position: sticky. A container div wraps the Vision Pro div and takes position: relative; a top margin pushes the container below the viewport, and the inner div gets top: 0. So scrolling brings the sticky element to a stop, the animation runs, and once the container has been fully scrolled through it carries the device up and out of view.

Moving the components with translate exposed a layering surprise: relying on natural element order let the browser's optimization engine stack the outer component above the middle one above the innermost. z-index restores the interleaved depth that gives Apple's version its look.

Vertical travel was the harder problem. Below the images' 960-pixel width, the components must rise far enough not to interfere with the second stage but not so far as to leave the viewport entirely. With the full image at 960px by 608px and the image width equal to the viewport width, an equation yields the height to base translations on:

--stage2-height: calc(min(100vw, 960px) * 608 / 960);

That equation fails when the viewport is shorter than 608px and wider than 960px, because the image width no longer equals 100vw. A matching equation for width has the same problem in reverse — each works only where the other does not. CSS does now have an if() function, but it doesn't work in Safari, and knocking out a second browser was not the goal, so a media query handles it:

:root {
  --stage2-height: calc(min(100vw, 960px) * 608 / 960);
  --stage2-width: calc(min(100vh, 608px) * 960 / 608);
}

@media screen and (max-height: 608px) {
  :root {
    --stage2-height: calc(var(--vid-width) * 608 / 960);
  }
}

The simpler realization: when the height is under 608px, it equals 100vh (ignoring the well-known complications of vh, particularly on iOS). So what was actually needed was:

:root {
  --stage2-height: calc(min(100vw, 960px) * 608 / 960);
}

@media screen and (max-height: 608px) {
  :root {
    --stage2-height: 100vh;
  }
}

Vertical translations based on the height of the second-stage graphics get the components out of the way, e.g.:

translate: 0 calc(var(--stage2-height) * -1 - 25vh);

Viewports narrower than 410px still required a height adjustment via media query.

Trading video for keyframes

CSS alone can neither start a video nor change its frame rate, so the flip-up is reproduced with keyframes that swap background images over time:

/* ... */

50% {
  background-image: url(imgs/video/00037.jpg);
  z-index: -1;
}

51% {
  background-image: url(imgs/video/00039.jpg);
  z-index: -1;
}

52% {
  background-image: url(imgs/video/00041.jpg);
  z-index: -1;
}

/* ... */

The full set of cssvideo keyframes runs to 60-some images and is too long to reproduce here. The cost is bandwidth: instead of one video file, the page downloads 60+ images. File numbers skip a value between iterations because the frame count was halved to avoid 120+ downloads; stitching a sprite might speed things up, but this is a proof of concept, not a production solution.

The initial scroll was choppy even when run locally, so this was added for every image, component images included:

<link rel="preload" as="image" href="imgs/video/00011.jpg">

That helped considerably — the server no longer had to parse the CSS before fetching all the images. The same view timeline as the first stage then drives an animation moving the device into place alongside the cssvideo animation, and the eyepieces appear to flip up:

animation: vpsf-move forwards, cssvideo forwards;
animation-timeline: --apple-vp, --apple-vp;

Tuning the timing with animation-range

A view timeline proved imprecise about where animations began and ended. animation-range fixed that. Applied to all the .parts:

animation-range: contain cover;

This keeps the Vision Pro inside the viewport before the animation starts (contain) and lets it keep running until fully out of view (cover). For the components that is desirable: they should be fully in view before rising, and their endpoint matters little. For the second stage the flip-up had to finish before leaving the screen, so it uses:

animation-range: cover 10% contain;

Here cover and 10% both refer to the animation's start — the cover keyword, pushed 10% later — while contain ensures the animation ends before the element begins its exit.

The working result, and a fallback video for browsers that don't support it yet, accompany the complete example.

What carried the build

The technique leans on several features at once. Scroll timelines attach an animation either to an element's scrolling or to the moment it enters view; animation-range sharpens when that happens; position: sticky holds an element on screen while it animates; grid layout overlaps elements without pulling them out of flow; and calc(), viewport units, custom properties and media queries each play a part, alongside HTML features like preload. Cutting-edge as much of this is, a fair amount is only relatively recent.