Skip to content
animorio
IT
All components

Trailing volume slider

Sliders, Hover, PhysicsGSAP, CSS onlyMediumCompressed weight: Demo 6.7 KBGSAP 28 KBFreeDownload the zip

The volume control of a music player, on very light grey, in the style of one-gesture micro-interactions: you drag the handle and the filled part follows a beat late, like a soft trail that stretches and pulls back. The volume number rolls, the speaker loses and gains its waves, past the ends the track stretches a few pixels on an elastic, and at zero the mute line draws itself.

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>
<!--
  "Trailing volume slider" 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 volume slider that leaves a trail</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" data-stage>
    <!-- the volume of a speaker in a player: drag the handle and the filled part follows a beat late,
         like a soft trail; past the ends the track stretches a few pixels and springs back -->
    <section class="card" data-card aria-label="Volume">
      <header class="card__head">
        <div class="cover" aria-hidden="true"><span></span></div>
        <div class="track-info">
          <p class="track-info__title">Low Tide</p>
          <p class="track-info__meta">Aurel Venn · Living room</p>
        </div>
        <p class="value" aria-hidden="true">
          <span class="value__digits" data-digits></span>
        </p>
      </header>

      <div class="row">
        <button class="speaker" type="button" data-speaker aria-label="Mute">
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path class="speaker__body" d="M4 9.5h3.2L11.5 6v12l-4.3-3.5H4z"></path>
            <path class="speaker__wave" data-wave="0" d="M14.4 10.2a2.6 2.6 0 0 1 0 3.6"></path>
            <path class="speaker__wave" data-wave="1" d="M16.4 8.3a5.3 5.3 0 0 1 0 7.4"></path>
            <path class="speaker__wave" data-wave="2" d="M18.4 6.4a8 8 0 0 1 0 11.2"></path>
            <path class="speaker__slash" data-slash d="M15 9.5l5 5M20 9.5l-5 5" pathLength="1"></path>
          </svg>
        </button>

        <div class="slider" data-slider role="slider" tabindex="0" aria-label="Volume" aria-valuemin="0" aria-valuemax="100" aria-valuenow="60">
          <div class="rail" data-rail>
            <div class="rail__track" data-track>
              <div class="rail__trail" data-trail></div>
              <div class="rail__fill" data-fill></div>
            </div>
            <div class="handle" data-handle><span class="handle__dot" data-knob></span></div>
          </div>
          <div class="ticks" data-ticks aria-hidden="true"></div>
        </div>
      </div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </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.

17 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 “Trailing volume slider” 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 very light grey background there is a white card with wide corners and a soft shadow: at the top the song’s cover, an indigo square with a blurred light, the title Low Tide with Aurel Venn · Living room below, and on the right the volume in large digits. Below, the speaker drawn with a thin stroke and its waves, the volume track with the round white handle, and under the track eleven thin ticks. Grabbed, the handle squashes sideways and the track thickens a little. As you drag it, the black part follows a beat late and between the two a light indigo trail is left that shortens as soon as the handle stops; going back the trail stays for a moment past the handle and pulls back. The number rolls digit by digit, with a column for hundreds and one for tens that open and close, the ticks under the filled part light up indigo and the one near the handle lifts, and at every round ten its tick gives a small jolt. The speaker has three waves above 66, two above 33, one below, and none at zero, where the mute line draws itself. Pulling past the ends the track stretches a few pixels towards the hand and, once let go, comes back on an elastic; the handle goes round again with a small bounce. A click on the speaker takes the volume away and gives back the one before. The autopilot pointer turns the volume up, down, pulls past the left end into mute, brings it back from the speaker and settles it halfway.

How it works

Two widths, one trail

The handle has its value v, the trail a value lag that chases it on every frame of the GSAP ticker by 1 minus e to the minus dt times TRAIL. The black part reaches the smaller of the two, the light trail the larger: so going forward the trail is ahead of the black, going back it stays past the handle.

The elastic at the ends

Past the end the extra is squashed with a hyperbolic tangent, STRETCH times tanh of the excess over four STRETCH: you pull a lot and the track stretches a few pixels. The stretch is a scaleX anchored on the opposite side; once let go, it goes back to zero with elastic.out.

Rolling digits

The number is three columns with the digits 0 to 9 stacked: GSAP moves each column to yPercent minus ten times the digit. Hundreds and tens have zero width when not needed and open with a transition, so the number does not jump sideways.

Mouse, finger and keyboard

Dragging uses pointer events with setPointerCapture and the track has touch-action: none, so on a phone the finger drags it instead of scrolling the page. The arrows move by STEP, Page Up and Down by ten, Home and End go to the ends; the speaker is a real button.

Values to change

NameFileDefaultWhat it changes
STARTscript.js60The starting volume, from 0 to 100.
TRAILscript.js7How fast the trail catches the handle: higher means a shorter trail.
STRETCHscript.js9How many pixels at most the track stretches when pulled past the ends.
HOLD_GROWscript.js1.5How much the track thickens while held.
ACCENTscript.js#5b5bf6The colour of the trail and the lit ticks.
FILLscript.js#18181bThe colour of the filled part.
STEPscript.js5How much the arrow keys move the volume.

Try them in the Playground

When to use it

In the player of a music or podcast app, in the control of a home speaker, in a video call app or an audio panel: anywhere a volume is set and the gesture should be felt, not just its number seen.

On phones

The card takes the width of the box minus the margins and the track remeasures to its real width, even when the phone turns. With a finger the handle drags as with the mouse, without scrolling the page.

With reduced motion

No trail, elastic or squash: the filled part follows the handle at once, the digits change without rolling, and the autopilot shows the values one after another.

Pitfalls

  • The trail runs on the GSAP ticker rather than a separate requestAnimationFrame, and the step is capped at 34 milliseconds: that way it stops with the page and a slow frame cannot make it jump.
  • Without touch-action: none on the track a phone takes the horizontal drag as a scroll and sends pointercancel halfway.
  • The stretch at the ends is a scaleX of the track, not of the card: the handle is moved by the same amount separately, otherwise it would squash too.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 26 October 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