
The layered button
Buttons, Hover, Physics
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.
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>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
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 siteThe 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.
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'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.
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.
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.
| Name | File | Default | What it changes |
|---|---|---|---|
STIFFNESS | script.js | 320 | The spring that carries the knob: higher is quicker. |
DAMPING | script.js | 24 | Lower lets the knob overshoot and come back. |
STEP | script.js | 11 | How wide each held sample is while compressed, in pixels. |
LEVELS | script.js | 6 | How many levels the compressed wave has above and below the middle: fewer, bigger steps. |
SMOOTH | script.js | 1.2 | The seconds the line of light takes to cross the wave. |
GLOW | script.js | 1 | How much the lossless wave glows. |
SPEED | script.js | 1 | 2 = the walk on its own twice as fast, 0.5 = half. |
LOOP | script.js | true | Goes through the walk again on its own. |
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.
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.
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.
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.
Tested on 15 November 2026
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.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.