Aduok Code

A Classic Car Showroom, Built from SVG Cars Drawn by One Function, Wheels That Turn by Distance over Radius, Suspension Pitch on Launch and Braking, and a Before and After Slider on a Registered CSS Variable

Introduction

This page is a showroom for a classic car restoration shop, and it is a single HTML file with no images and no animation library. Six cars from the late sixties sit in a row at the bottom. Pick one and the current car pulls away with a puff of exhaust and a little dust, two racing stripes sweep across the screen, and the new car rolls in from the side, dips its nose as it brakes, and flashes its headlights. The name rises letter by letter, the year rolls like an odometer, the specs count up, and a horsepower needle swings into place with a small overshoot.

The page rests on five ideas: every car is drawn by one function from a few shared SVG path pieces, the car moves with the Web Animations API so every step can be awaited, the wheels turn by exactly the distance travelled divided by the wheel radius so the tyres never slide, the body tilts on its own element so it can squat and dive while the wheels stay level, and a registered CSS variable drives a clip-path that reveals the rusty barn find under the finished car.

What you will learn

How to build several different SVG drawings from shared path strings — how to keep clipPath ids unique when one drawing is used many times — how to chain animations with element.animate and await — how to sync wheel rotation to movement — how to animate SVG groups around their own centre with transform-box — how to animate a custom property with @property — and how to use a running animation as a pausable autoplay timer.

The cars are original drawings

Each car is a simple side profile drawn with SVG paths, not a photo and not traced from one. The model names are only labels. The shop stories, paint names and shop hours are invented for the demo, and the horsepower and 0 to 60 numbers are rough period figures.

01
Part One
Six Cars from One Function

Step 1 — A Body Path Built from Four Pieces

Every car lives in the same 800 by 250 box, faces left, and has its front wheel centred at x = 180 and its rear wheel at x = 610. Because those numbers never change, the body outline can be split into pieces and glued back together. The nose and the tail with both wheel arches are the same for most cars. Only the roof changes between a fastback, a notchback and a convertible. A pointed nose and a matching close piece turn one car into the long-nosed winged one.

JavaScript
const NOSE    = 'M 30 150 C 30 131 38 125 64 123 ';
const NOSE_P  = 'M 4 162 C 6 146 26 135 70 128 ';          // pointed nose
const TAIL    = ' C 766 111 770 140 768 170 L 762 182'
              + ' L 664 182 A 54 54 0 0 0 556 182'          // rear wheel arch
              + ' L 234 182 A 54 54 0 0 0 126 182 L 46 182'; // front wheel arch
const CLOSE   = ' C 32 181 28 166 30 150 Z';
const CLOSE_P = ' C 20 181 4 174 4 162 Z';

const SHAPES = {
  fastback:    { roof: 'L 296 113 C 330 96 360 75 392 65 C 430 56 482 55 515 60 C 565 72 628 99 700 108 L 752 110', glass: '...' },
  notch:       { roof: 'L 300 113 C 334 97 362 77 394 67 C 430 59 478 58 508 63 C 532 77 556 95 576 103 L 752 108', glass: '...' },
  convertible: { roof: 'L 752 110', glass: '...', extra: '... seats, steering wheel, folded top ...' }
};

const d = (c.pointy ? NOSE_P : NOSE) + SHAPES[c.style].roof + TAIL + (c.pointy ? CLOSE_P : CLOSE);

The wheel arches are the arc commands in the tail piece. Each one runs from one side of a wheel to the other with a radius of 54, and the flags 0 0 0 make the arc bulge upward, so the body is cut around the tyre. A dark half circle drawn behind the body fills each arch, which reads as the inside of the wheel well instead of an empty hole.

Paint, shading and chrome from shared gradients

The body path is drawn twice. The first copy is filled with the car colour. The second copy is filled with a vertical gradient that goes from a soft white highlight at the top to a dark shadow at the bottom, so a flat colour turns into a rounded panel. The gradients for shading, chrome, glass, wheel rims and the headlight beam are defined once in a zero-size SVG at the top of the page, and every car points at them by id.

HTML
<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
  <defs>
    <linearGradient id="g-shade" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0"   stop-color="#fff" stop-opacity=".5"/>
      <stop offset=".22" stop-color="#fff" stop-opacity=".1"/>
      <stop offset=".5"  stop-color="#000" stop-opacity="0"/>
      <stop offset=".8"  stop-color="#000" stop-opacity=".22"/>
      <stop offset="1"   stop-color="#000" stop-opacity=".5"/>
    </linearGradient>
    <linearGradient id="g-chrome"> ... </linearGradient>
    <radialGradient id="g-rim"> ... </radialGradient>
    <filter id="f-rough">
      <feTurbulence type="fractalNoise" baseFrequency=".08" numOctaves="3" seed="3"/>
      <feDisplacementMap in="SourceGraphic" scale="14"/>
    </filter>
  </defs>
</svg>
Do not hide the defs SVG with display: none

Some browsers stop painting gradients that live inside an element with display: none. A width and height of 0 with position: absolute keeps the SVG out of the layout while its gradients still work.

Stripes clipped to the body, with a unique id every time

Racing stripes are plain rectangles that run past the car. To trim them to the paint, each car has its own clipPath made from its body path. The same car is drawn three times on the page, in the main view, in the before view and in the thumbnail row, and SVG ids are global to the whole document, so a counter gives every drawing a fresh id. Without it, every stripe would be clipped by whichever car was drawn first.

JavaScript
let uid = 0;

function carSVG(c, o = {}) {
  const id = 'clip' + (++uid);
  const before = !!o.before;
  const stripe = before ? '' : STRIPES[c.stripe](c.stripeColor);
  return `<svg viewBox="0 0 800 250" overflow="visible" aria-hidden="true">
    <defs><clipPath id="${id}"><path d="${d}"/></clipPath></defs>
    <g class="chassis">
      <path d="${d}" fill="${c.color}"/>
      <g clip-path="url(#${id})">${stripe}${before ? RUST : ''}</g>
      <path d="${d}" fill="url(#g-shade)"/>
      <path d="${sh.glass}" fill="url(#g-glass)" stroke="#cfd4d8" stroke-width="2.5"/>
      ... door lines, handle, mirror, bumpers, lights, spoiler, scoop, wing ...
    </g>
    ${wheel(180, before)}${wheel(610, before)}
  </svg>`;
}

Notice that the wheels are outside the chassis group. That is deliberate. The chassis is the part that will tilt when the car accelerates and brakes, and the wheels must stay on the floor while it does. Small options in the data object add the extras: spoiler draws a black lip on the tail, scoop adds a hood scoop, wing adds two uprights and a blade, and hidden removes the round headlamp for cars with hidden headlights.

The before version uses the same function with before set to true. It skips the stripes, adds a group of rust blotches and a grey primer patch clipped to the body, roughens their edges with the turbulence filter, darkens the rims and draws a crack across the side window.

02
Part Two
The Stage and Its Nested Wrappers

Step 2 — One Wrapper per Kind of Movement

The car is moved by four different things: the mouse parallax, the drive in and out, a tiny engine idle shake, and the rev when you click. If they all wrote to the same transform, each one would overwrite the others. So each movement gets its own element, nested one inside the next, and each element owns exactly one transform.

HTML
<section class="stage" id="stage">          <!-- fixed 800/250 box, holds --split -->
  <div class="park">                          <!-- mouse parallax -->
    <div class="rig" id="rig">                <!-- drive in and out -->
      <div class="shadow"></div>
      <div class="idle">                      <!-- engine idle shake -->
        <div class="layer after"  id="layerAfter"></div>
        <div class="layer before" id="layerBefore"></div>
      </div>
    </div>
  </div>
  <div class="fx" id="fx"></div>             <!-- exhaust and dust -->
  <div class="split" id="split">...</div>     <!-- before and after handle -->
</section>
CSS
.stage { position: absolute; left: 51%; top: 1%; width: min(56vw, 104vh, 1000px);
         aspect-ratio: 800 / 250; transform: translateX(-50%); }
.park  { position: absolute; inset: 0;
         transform: translate(calc(var(--mx) * 14px), calc(var(--my) * 6px)); }
.rig   { position: absolute; inset: 0; }
.idle  { position: absolute; inset: 0; animation: idle .13s linear infinite; }
.rig.moving .idle { animation: none; }

@keyframes idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(.6px); } }

The stage has the same aspect ratio as the SVG viewBox, so a point in the drawing always maps to the same percentage of the stage. That is what lets the exhaust puffs be placed with percentages later. The shadow sits inside the rig so it travels with the car, but outside the idle wrapper so it does not shake. The idle shake is only 0.6 pixels, which you feel more than see.

Give every kind of movement its own element. Transforms on separate elements add up; transforms on the same element fight.

03
Part Three
Driving Out and Driving In

Step 3 — Wheels That Turn by Distance over Radius

A car that slides across the screen with spinning wheels looks fake because the spin speed has nothing to do with the speed of the car. A rolling wheel turns by exactly the distance it travels divided by its radius, in radians. So the move function measures the distance in pixels, measures the wheel radius in pixels on the current screen, and builds a rotation with the same duration and the same easing as the movement. When the car speeds up, the wheels speed up. When it brakes, they slow down with it.

JavaScript
const vwPx = v => v * innerWidth / 100;

async function move(fromVw, toVw, dur, easing, pitch) {
  const fromPx = vwPx(fromVw), toPx = vwPx(toVw);

  // wheel radius is 46 units out of 800 in the drawing
  const rPx = 46 / 800 * stage.getBoundingClientRect().width;
  const deg = ((toPx - fromPx) / rPx) * 180 / Math.PI;

  const opts = { duration: dur, easing };
  const a = rig.animate(
    [{ transform: `translateX(${fromPx}px)` }, { transform: `translateX(${toPx}px)` }],
    { ...opts, fill: 'forwards' });

  rig.querySelectorAll('.spokes').forEach(s =>
    s.animate([{ transform: 'rotate(0deg)' }, { transform: `rotate(${deg}deg)` }], opts));

  rig.querySelectorAll('.chassis').forEach(c =>
    c.animate(pitch, { duration: dur, easing: 'ease-out' }));

  await a.finished;
  rig.style.transform = `translateX(${toPx}px)`;   // keep the end position
  a.cancel();                                      // and drop the animation
}

The sign takes care of itself. Moving left gives a negative distance, which gives a negative angle, which is an anticlockwise turn, and that is the way a wheel spins when a car drives to the left. Driving backwards gives a positive distance and a clockwise turn.

The last two lines matter. An animation with fill: forwards keeps holding its end value for as long as it exists, and every new one stacks on top. Copying the end value into the inline style and then cancelling the animation leaves the element in the right place with nothing left running.

Rotating an SVG group around its own centre

By default an SVG element rotates around the top left of the whole drawing, not around itself. Setting transform-box: fill-box makes percentages and keywords in transform-origin refer to the element's own box. The spokes group also contains an invisible circle with the same radius as the rim. Five spokes are not symmetric, so without that circle the box would be a little off-centre and the wheel would wobble as it turns.

CSS
.spokes  { transform-box: fill-box; transform-origin: center; }
.chassis { transform-box: fill-box; transform-origin: 50% 100%; }

Squat on launch, dive on braking

The car faces left, so a positive rotation lifts the nose. When it pulls away, the weight moves back and the nose rises by about 1.8 degrees. When it arrives, it holds level for most of the trip, then dives forward as the easing slows it down, rebounds a little past level and settles. Those are just keyframes with offsets that line up with the slow end of the easing curve.

JavaScript
function driveOut(dir) {
  rig.classList.add('moving');
  rig.classList.toggle('rev', dir < 0);            // white reverse lights
  if (dir > 0) { puffs(14, true); dust(); }
  speedLines(dir);
  const pitch = [
    { transform: 'rotate(0)' },
    { transform: 'rotate(1.8deg)', offset: .3 },    // nose up
    { transform: 'rotate(.8deg)' }
  ];
  return move(0, dir > 0 ? -125 : 120, 900, 'cubic-bezier(.55,0,.85,.3)', pitch);   // ease-in
}

async function driveIn(dir) {
  const pitch = [
    { transform: 'rotate(0)' },
    { transform: 'rotate(0)',       offset: .55 },
    { transform: 'rotate(-2.2deg)', offset: .8 },   // nose dives
    { transform: 'rotate(.7deg)',   offset: .92 },  // rebound
    { transform: 'rotate(0)' }
  ];
  await move(dir > 0 ? 120 : -125, 0, 1250, 'cubic-bezier(.12,.7,.22,1)', pitch);    // ease-out
  rig.style.transform = '';
  rig.classList.remove('moving', 'rev');
  flashLights();
}

Leaving uses an ease-in curve, slow at first and fast at the end, like a car pulling away. Arriving uses a strong ease-out, fast at first and gentle at the end, like a car braking. Going to the previous car flips the direction, so the car reverses out to the right with its reverse lights on.

04
Part Four
Exhaust, Dust, Speed Lines, and Stripes

Step 4 — Small Elements That Remove Themselves

All four effects follow the same pattern: create a small element, give it a random start, animate it, and remove it when its animation finishes. The finished promise makes the clean-up one line, so the page never collects leftover nodes no matter how often you switch cars.

JavaScript
// tailpipe sits at about (772, 183) in the 800 by 250 drawing
function puffs(n = 1, big = false) {
  for (let i = 0; i < n; i++) {
    const p = document.createElement('span');
    p.className = 'puff';
    p.style.left = (772 / 800 * 100) + '%';
    p.style.top  = (183 / 250 * 100) + '%';
    fx.appendChild(p);
    p.animate([
      { transform: 'translate(0,0) scale(.3)', opacity: big ? .9 : .55 },
      { transform: `translate(${rand(30, big ? 160 : 70)}px, ${rand(-40, -10)}px) scale(${big ? rand(2.5, 5) : rand(1.4, 2.4)})`, opacity: 0 }
    ], { duration: rand(1000, 1700), delay: i * rand(20, 60), easing: 'cubic-bezier(.2,.7,.3,1)', fill: 'backwards' })
      .finished.then(() => p.remove());
  }
}

A puff is a round span with a radial gradient that fades to transparent, so it looks soft without a blur filter. One small puff every 1.3 seconds makes the parked car look like it is running, and a burst of fourteen large ones goes off when it pulls away. Dust is the same idea with small brown dots thrown back and up from the rear tyre. Speed lines are thin gradient bars that streak across the showroom in the opposite direction to the car.

The racing stripe wipe is two tall skewed bars, one in the accent colour and one in near-black, that slide across the whole showroom one after the other. They sit above the giant outline word but below the car and the text, so they read as a stripe painted on the wall behind the car.

JavaScript
function wipe(dir) {
  const W = innerWidth;
  wipeBands.forEach((b, i) => {
    const from = dir > 0 ? W * 1.1 : -W * .5;
    const to   = dir > 0 ? -W * .5 : W * 1.1;
    b.animate(
      [{ transform: `translateX(${from}px) skewX(-18deg)` },
       { transform: `translateX(${to}px) skewX(-18deg)` }],
      { duration: 1150, delay: 120 + i * 110, easing: 'cubic-bezier(.65,0,.35,1)' });
  });
}
05
Part Five
Letters, Odometer, Counters, and Gauge

Step 5 — Masked Letters

The car name and the giant outline word behind the car are split into one span per letter, grouped into one span per word. The word span has overflow: hidden, which acts as a mask. Each letter starts below the mask and slides up into view with a short delay after the one before it. Going out, they slide up and away through the top. Words stay in their own spans so the browser can still wrap a long name between words, never in the middle of one.

JavaScript
function setSplit(el, text) {
  el.setAttribute('aria-label', text);
  el.innerHTML = text.split(' ')
    .map(w => `<span class="w" aria-hidden="true">${[...w].map(ch => `<span class="ch">${ch}</span>`).join('')}</span>`)
    .join(' ');
}

function charsIn(el, { stagger = 28, dur = 950, from = '110%' } = {}) {
  return Promise.all([...el.querySelectorAll('.ch')].map((c, i) => c.animate(
    [{ transform: `translateY(${from}) rotate(8deg)` }, { transform: 'none' }],
    { duration: dur, delay: i * stagger, easing: 'cubic-bezier(.16,1,.3,1)', fill: 'backwards' }
  ).finished));
}

The aria-label on the heading holds the full name, and the letter spans are hidden from screen readers, so the name is read as a word and not spelled out. The fill: backwards option makes each letter wait in its start position during its delay, otherwise the later letters would flash in their final place before their turn came.

A rolling odometer for the year

The year is four columns. Each column is a stack of the digits 0 to 9, one line tall each, inside a box that is one line tall with overflow: hidden. To show a digit, the column moves up by that many lines. A CSS transition does the rolling, and a delay that grows by 90 milliseconds per column makes the digits settle one after the other, like a real counter.

JavaScript
function setYear(y) {
  String(y).split('').forEach((d, i) => {
    odoCols[i].style.transitionDelay = (i * 90) + 'ms';
    odoCols[i].style.transform = `translateY(-${d}em)`;
  });
}

Counters and a needle with a spring

The three specs count from their old value to the new one with requestAnimationFrame and an ease-out of 1 - (1 - p) to the power of 4, so the numbers race at first and settle gently. The horsepower gauge is drawn by a small function that places tick marks and labels with sine and cosine around a 240 degree arc. The needle is rotated by CSS with a transition whose curve, cubic-bezier(.34, 1.56, .64, 1), goes past 1, so the needle overshoots its mark and swings back like a real dial.

CSS
.gauge .needle {
  transform-origin: 100px 100px;      /* the dial centre, in viewBox units */
  transition: transform 1.4s cubic-bezier(.34, 1.56, .64, 1);
}
.gauge .prog {                        /* the coloured arc */
  transition: stroke-dashoffset 1.4s cubic-bezier(.34, 1.3, .64, 1);
}

The coloured arc under the ticks uses the classic dash trick. Its dash length is set to the full length of the path from getTotalLength, and the dash offset hides a share of it. An offset of the full length shows nothing, and an offset of zero shows the whole arc. When the car changes, the needle snaps to zero with a faster transition, then swings up to the new value once the new car arrives.

06
Part Six
The Before and After Slider

Step 6 — A Registered Variable Drives the Cut

The before layer sits exactly on top of the finished car and is cut with clip-path. The cut position is a CSS variable called --split. Normally a custom property cannot be animated, because the browser does not know it is a number and swaps the value instantly. Registering it with @property as a percentage tells the browser its type, and then a transition on --split works like a transition on any other length.

CSS
@property --split { syntax: '<percentage>'; inherits: true; initial-value: 0%; }

.stage { transition: --split 1s cubic-bezier(.76, 0, .24, 1); }
.stage.dragging { transition: none; }

.layer.before {
  clip-path: inset(-40% calc(100% - var(--split)) -10% -40%);
  filter: grayscale(.65) sepia(.5) contrast(.92) brightness(.9);
}

.split { left: var(--split); }   /* the handle follows the same variable */

The negative insets on the top, bottom and left let the cut reach past the edges of the stage, so the antenna, the wing and the headlight beam are not trimmed. Turning the toggle on sets --split to 50% and the before layer slides in from the left over one second. Turning it off sets it back to 0% and it slides away. A sepia and grayscale filter on the whole before layer gives it the faded barn-find look on top of the rust drawn in the SVG.

Dragging uses pointer capture, so the handle keeps following the pointer even when it leaves the stage. While dragging, the dragging class turns the transition off so the cut follows the finger with no lag, and it is turned back on when the pointer is released.

JavaScript
function startDrag(e) {
  stage.classList.add('dragging');
  stage.setPointerCapture(e.pointerId);
  const r = stage.getBoundingClientRect();
  const update = ev => {
    const pct = Math.max(2, Math.min(98, (ev.clientX - r.left) / r.width * 100));
    stage.style.setProperty('--split', pct + '%');
  };
  update(e);
  const up = () => {
    stage.classList.remove('dragging');
    stage.removeEventListener('pointermove', update);
    stage.removeEventListener('pointerup', up);
    stage.removeEventListener('pointercancel', up);
  };
  stage.addEventListener('pointermove', update);
  stage.addEventListener('pointerup', up);
  stage.addEventListener('pointercancel', up);
}
07
Part Seven
One Function That Runs the Change

Step 7 — Choreography with async and await

Every way of changing car, the arrows, the keyboard, the mouse wheel, a swipe, a thumbnail or autoplay, calls the same go function. Because every animation returns a promise, the whole sequence reads top to bottom like a script: start the exits together, wait for the car to leave, swap the drawing and the colours while nothing is on screen, then start the arrivals. A busy flag ignores new requests until the car has stopped.

JavaScript
async function go(n, dir) {
  n = (n + CARS.length) % CARS.length;
  if (busy || n === idx) return;
  busy = true;
  dir = dir || (n > idx ? 1 : -1);

  stopAuto();
  setCompare(false);
  setStripActive(n);          // the thumbnail reacts right away
  hpGauge.set(0, true);       // needle drops fast
  textOut();
  ghostOut(dir);
  wipe(dir);
  await driveOut(dir);        // wait until the old car is off screen

  idx = n;
  const c = CARS[n];
  renderCar(c);               // swap the SVGs while nothing is visible
  applyTheme(c);              // accent colour, paint card, counter
  const arrive = driveIn(dir);
  ghostIn(c, dir);
  setTimeout(() => textIn(c), 420);
  await arrive;

  busy = false;
  startAuto();
}

The accent colour is also a registered property, declared with the color syntax, so setting it on the root element fades the glow behind the car, the needle, the stripe, the call-to-action button and the progress bar to the new car's colour at the same time, with one transition on :root.

An animation used as an autoplay timer

Autoplay does not use setTimeout. The progress bar under the active thumbnail is a seven second scaleX animation, and when it finishes, the next car is called. That one animation is both the visible timer and the real timer, so they can never drift apart. Pausing on hover, when the before view is open or when the tab is hidden is a single call to pause, and play continues from exactly where it stopped.

JavaScript
const AUTO = 7000;

function startAuto() {
  autoAnim && autoAnim.cancel();
  autoAnim = stripFill.animate(
    [{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }],
    { duration: AUTO, fill: 'forwards' });
  autoAnim.onfinish = () => next();
  if (hovering || compare) autoAnim.pause();
}

showroom.addEventListener('pointerenter', () => { hovering = true;  autoAnim && autoAnim.pause(); });
showroom.addEventListener('pointerleave', () => { hovering = false; if (autoAnim && !compare) autoAnim.play(); });

If a progress bar shows the time left, let the progress bar be the timer.

08
Part Eight
Two Bugs Worth Knowing

Step 8 — The Disappearing Description and the Wide Phone Page

In the first version, the description under the car name vanished after the first change and never came back, even though the new text was in the page. The exit animation faded it to opacity 0 with fill: forwards, which keeps that value for as long as the animation exists. The entry animation used fill: backwards, so it only held its values until it finished. After that, the old forwards animation was still there underneath, and it set the opacity back to 0.

JavaScript
function textIn(c) {
  // clear what textOut left behind before starting the entry
  [make, desc].forEach(el => el.getAnimations().forEach(a => a.cancel()));
  ...
}
Every forwards fill needs an owner that cancels it

An animation with fill: forwards is not done when it finishes. It keeps overriding the style until it is cancelled or the element is removed. The letters did not have this problem because setSplit replaces them with new elements. The description and the make line are reused, so their old animations had to be cancelled by hand.

The second bug only showed on phones: the whole page was wider than the screen and the text ran off the right edge. The page is a CSS grid, and a grid item will not shrink below the width of its content by default. The thumbnail row holds six cars of 120 pixels each, so it pushed its grid track to about 800 pixels, and every other row became that wide too. One rule fixes it.

CSS
.app > * { min-width: 0; }   /* let grid items shrink; the strip scrolls instead */
09
Part Nine
Phones, Cursor, and Reduced Motion

Step 9 — The Finishing Layer

Below 900 pixels the absolute layout turns into one column: the car on top, the name and specs below it, the gauge next to the paint card and the toggle, and the thumbnails in a row that scrolls sideways. The mouse wheel no longer changes cars there, so the page can scroll normally. A swipe on the car of more than 60 pixels goes to the next or previous car, and the stage uses touch-action: pan-y so vertical scrolling still works.

On a device with a fine pointer, the system cursor is replaced by a ring that follows the mouse with a little lag and a small dot that follows it exactly. Over a link or a button the ring grows. Over the car it becomes a solid circle that says REV, and a click revs the engine: the body rocks, the idle wrapper shakes, a cloud of exhaust goes off, the headlights flash and the needle jumps into the red before falling back. The same loop eases the mouse position into --mx and --my, which move the car one way and the outline word the other way for a gentle depth effect.

The page opens with a short loader: a dark screen with a rev counter that blips twice into the red while a percentage counts to 100, then the screen lifts away with a clip-path inset and the first car drives in. A click anywhere skips it.

JavaScript
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;

// every animate call uses this when reduce is true
const opts = { duration: reduce ? 1 : dur, easing };

// and the effects return early
function puffs(n = 1, big = false) { if (reduce) return; ... }

With reduced motion on, the loader is skipped, the grain, idle shake and autoplay are turned off, the effects do not run, and every animation gets a duration of 1 millisecond. The content still changes and every promise still resolves, so the same go function works without a separate code path.

Tuning Reference

ValueExampleEffect
Drawing box800 × 250Every car shares it; the stage uses the same aspect ratio
Wheel centresx = 180 and x = 610Arches, wells and wheels all line up with these
Wheel radius46Used to turn distance into wheel angle
Drive out900ms, cubic-bezier(.55,0,.85,.3)Ease-in, like a car pulling away
Drive in1250ms, cubic-bezier(.12,.7,.22,1)Ease-out, like a car braking
Launch squatrotate(1.8deg)How far the nose lifts when leaving
Brake diverotate(-2.2deg) at 80%How far the nose dips before settling
Needle curvecubic-bezier(.34,1.56,.64,1)A value above 1 makes the needle overshoot
Letter stagger28msDelay between letters in the car name
Odometer delay90ms per digitHow far apart the year digits settle
Autoplay7000msLength of the progress bar and the time per car
Idle puffevery 1300msHow often the parked car breathes exhaust
Swipe threshold60pxHorizontal drag needed to change car
Stack breakpoint900pxWidth below which the layout becomes one column

Full Source Code

The whole project is a single self-contained HTML file with its markup, styles and script together and no build step. The only external request is the Google Fonts stylesheet for Anton, Inter and Instrument Serif, and the page falls back to system fonts if it does not load. It needs a browser with the Web Animations API, @property and transform-box, which means any current Chrome, Edge, Safari or Firefox.

HTML — classic-car-showroom.html (complete)
// Full source available in the Aduok GitHub repository
// https://github.com/aduok/aduok-code-snippets/blob/main/blog/classic-car-showroom.html
Want to try it yourself?Open the live classic-car-showroom.html file