Skip to content
animorio
IT
All components

Lossless audio switch

Toggles, Hover, PhysicsCanvas, GSAP, CSS onlyAdvancedCompressed weight: Demo 10 KBGSAP 28 KBFreeDownload the zip

The Lossless switch of an invented music app, Ondine: a glass track with a brushed metal knob that catches the pointer's light. Underneath the song plays as a wave: off it is compressed, in steps, with few levels and the samples showing as thin stems. Turned on, the app matches the source for an instant, then a line of light crosses the wave and behind it the steps melt into a smooth glowing curve, while format, bit depth, sample rate and data per hour roll to their new values and the Hi-Res badge arrives. The knob can be dragged and the wave follows the hand.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Lossless audio switch" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>The lossless audio switch with the stepped wave smoothing out</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the Lossless switch of a music app, Ondine: a glass track with a brushed metal knob. Under it the song plays as
         a wave. Off, the wave is compressed: coarse steps, a few levels, the samples showing as thin stems. Turned on,
         the app matches the source for a moment, then a line of light sweeps across the wave and behind it the steps
         melt into a smooth curve; the format, the bit depth, the sample rate and the data per hour roll to new values.
         The knob can be dragged: the wave follows the hand, and let go it snaps to the nearest side on a spring. -->
    <section class="card" data-card aria-label="Ondine, audio quality">
      <span class="card__light" data-light aria-hidden="true"></span>
      <span class="card__rim" aria-hidden="true"></span>

      <header class="card__head">
        <span class="card__brand">
          <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M1.5 8c1.6 0 1.6-4.5 3.2-4.5S6.3 12.5 8 12.5s1.6-9 3.3-9 1.6 4.5 3.2 4.5"/></svg>
          Ondine
        </span>
        <span class="card__crumb">Audio quality</span>
      </header>

      <div class="row">
        <div class="row__text">
          <span class="row__head">
            <label class="row__title" for="lossless">Lossless</label>
            <span class="badge" data-badge aria-hidden="true"><span class="badge__in">Hi-Res<span class="badge__shine" data-shine></span></span></span>
          </span>
          <span class="row__sub roll" data-sub><span class="roll__line">AAC · 256 kbps</span></span>
        </div>
        <button class="switch" id="lossless" type="button" role="switch" aria-checked="false" data-switch>
          <span class="switch__track" aria-hidden="true">
            <span class="switch__fill" data-fill></span>
            <span class="switch__glass"></span>
          </span>
          <span class="knob" data-knob aria-hidden="true">
            <span class="knob__body" data-body>
              <span class="knob__metal"></span>
              <span class="knob__spec" data-spec></span>
              <span class="knob__glint" data-glint></span>
            </span>
          </span>
        </button>
      </div>

      <div class="scope" data-scope>
        <canvas class="scope__wave" data-canvas aria-hidden="true"></canvas>
        <span class="scope__edge" aria-hidden="true"></span>
        <span class="scope__tag roll" data-tag><span class="roll__line">Compressed</span></span>
        <span class="scope__track">Nightglass · Halden</span>
      </div>

      <dl class="stats">
        <div class="stat">
          <dt>Bit depth</dt>
          <dd class="roll" data-val="bits"><span class="roll__line">16-bit</span></dd>
        </div>
        <div class="stat">
          <dt>Sample rate</dt>
          <dd class="roll" data-val="rate"><span class="roll__line">44.1 kHz</span></dd>
        </div>
        <div class="stat">
          <dt>Per hour</dt>
          <dd class="roll" data-val="size"><span class="roll__line">115 MB</span></dd>
        </div>
      </dl>
    </section>
    <p class="sr" aria-live="polite" data-live></p>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

31 values to change

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Lossless audio switch” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On a black page a dark card with round corners and a thin edge catching the light slowly rises: at the top the wave mark and the name of the invented app, Ondine, and on the right ‘Audio quality’. Below, the ‘Lossless’ row with ‘AAC · 256 kbps’ in grey and on the right the switch: a dark glass track with a brushed metal knob, with very fine rings, its highlight shifting towards the pointer. Further down a sunken panel where the song plays, ‘Nightglass · Halden’: a grey stepped wave, the samples held flat, few levels and a thin stem for each sample, labelled ‘Compressed’; at the bottom three values, Bit depth 16-bit, Sample rate 44.1 kHz and Per hour 115 MB. The finger presses the switch: the knob squashes a little, runs to the other side stretching, passes the end by a pixel and settles, and a flash of light crosses its metal; behind it the track fills with a mint and periwinkle gradient and a glow lights up. The line under Lossless says ‘Matching source’ with a shimmer running through it, then rolls, letter by letter, to ‘ALAC · 24-bit / 96 kHz’. Meanwhile a line of light crosses the wave from left to right: behind it the steps get finer and the levels more numerous until the wave becomes a smooth mint and periwinkle curve that glows, with a veil of light underneath; the stems fade, the label turns to ‘Bit-perfect’ and the three values roll one after the other to 24-bit, 96 kHz and 1.2 GB. Last, next to Lossless, the Hi-Res badge arrives with a bounce and a reflection crossing it. Then the finger drags the knob halfway back: the wave turns back to steps in the part the knob leaves, and let go the knob returns on its spring and the wave smooths out again. At the end the switch turns off, the badge leaves, the values roll back and the wave goes back to steps; the loop starts over. The knob can be pressed, dragged or flicked, the Lossless label touched, or the keyboard used.

How it works

The wave with changing resolution

The wave is drawn on a canvas every frame as a sum of three sines moving in time inside an envelope. For every half pixel the code works out how lossless that point already is (s, from 0 to 1): the width of the held sample is STEP times (1 - s) to the 1.5, and x is rounded to that step; the levels are LEVELS plus (220 - LEVELS) times s cubed, and y is rounded to those levels. So with s at 0 come the steps, with s at 1 the smooth curve, and in between the resolution really grows.

The line of light passing

A single number, q, says how far the smooth part has come. The front is q times (width plus two bands) minus one band, and each point's s is a smoothstep of its distance from the front: the transition fades over a fifth of the panel. The trace takes a horizontal gradient with its stops on the front (mint and periwinkle behind, grey ahead), a halo drawn twice, wider, in lighter blending, a veil of light under the curve clipped to the front and a bright vertical line on the front.

The knob on a spring

The knob's position is not a tween: it is a spring integrated by hand on the GSAP ticker (stiffness 320, damping 24, two steps per frame, step capped at a thirtieth of a second). The movement sits on the .knob element, the shape on its child .knob__body: it widens and flattens with speed and pressure, so it runs stretched and bumps by a pixel. The track's fill and the glow under the card take the same position as the CSS variable --p.

Dragging and flicking

With setPointerCapture the knob follows the finger along the track, with a little rubber band past the ends, and while dragging q equals the position: the wave smooths out or goes back to steps under the hand. Let go, if the speed is over three runs per second the flick's direction wins, otherwise the nearest side; if the state does not change, the wave goes back where it was in half a second without rolling anything.

The values that roll

Each value is a row of letters in inline-block spans inside a box with hidden overflow: the old row leaves upwards letter by letter, the new one comes in from below with back.out and a 16 millisecond stagger. Turning on, the format line first goes through ‘Matching source’ with a shimmer made with background-clip text, and the three values, the label and the Hi-Res badge are calls on a single timeline, which is cancelled whole if you change your mind halfway.

Values to change

NameFileDefaultWhat it changes
STIFFNESSscript.js320The spring that carries the knob: higher is quicker.
DAMPINGscript.js24Lower lets the knob overshoot and come back.
STEPscript.js11How wide each held sample is while compressed, in pixels.
LEVELSscript.js6How many levels the compressed wave has above and below the middle: fewer, bigger steps.
SMOOTHscript.js1.2The seconds the line of light takes to cross the wave.
GLOWscript.js1How much the lossless wave glows.
SPEEDscript.js12 = the walk on its own twice as fast, 0.5 = half.
LOOPscript.jstrueGoes through the walk again on its own.

Try them in the Playground

When to use it

For the app or site of a music streaming service, a headphones and hi-fi shop or a podcast app: the audio quality setting. It also suits any switch that changes the quality of something (HD video, original photos, full sync) and needs to show the difference.

On phones

The same card with adapted sizes: it is as wide as the box allows, the wave panel gets shorter with the screen's height and the canvas redraws at the new size; the knob can be dragged and flicked with a finger and the track does not scroll the page.

With reduced motion

The knob is on the other side at once, without travelling; the wave does not flow and instead of the line of light it fades out and back in already smooth or already stepped; the words and values change with a fade and the badge appears without a bounce.

Pitfalls

  • Rounding only y made the compressed wave just look grainy: real steps come from holding the sample on x too, with a width that shrinks together with the levels, or half the transformation is lost.
  • The first halo was a wide line at low opacity and on black it looked like a dirty outline: drawn twice in lighter blending it becomes light.
  • The three values started with separate delayedCalls and changing mind halfway they rolled to the wrong numbers: now they are calls on the same timeline as the front, which is cancelled whole.
  • The click following a tap or a drag toggled a second time: the click only counts for the keyboard, if it does not come within 600 milliseconds of a pointer.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 10 KB; the libraries: GSAP 28 KB.

Testing

Tested on 15 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components