
The elastic button
Buttons, Hover, Text
The Add to playlist button of a music app, on black. Pressed, the pill widens and shows the playlist’s stack of covers, three already piled up and fanned out; the song’s cover lifts off its row, arcs over and drops on top of the stack, which squashes and settles on a spring, the 23 songs count rolls to 24 songs and the button says Added to Night Drive with a drawn check. A second tap takes the song out and the cover flies back to its row.
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>
<!--
"Add to playlist button" 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 Add to playlist button with the cover that drops onto the stack</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 Add to playlist button of a made-up music app: pressed, the pill widens and shows the playlist's stack of
covers, the song's cover lifts off its row, arcs over and drops on the stack, the stack squashes and settles,
the count rolls and the button says Added to Night Drive with a drawn check; a second press takes it out -->
<div class="wrap" data-wrap>
<!-- the song: its cover sits in a soft socket that shows when the cover leaves -->
<div class="track" data-track>
<span class="socket" data-socket>
<span class="socket__ghost art art--harbour" aria-hidden="true"></span>
<span class="cover" data-cover>
<span class="cover__face art art--harbour" aria-hidden="true"></span>
<span class="cover__sheen" data-sheen aria-hidden="true"></span>
</span>
</span>
<span class="track__text">
<b data-title>Glass Harbour</b>
<i data-artist>Mira Vane · 3:41</i>
</span>
<svg class="track__wave" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 10v4M9 7v10M13 9v6M17 6v12M21 10v4"></path></svg>
</div>
<div class="pill" data-pill>
<div class="pill__clip">
<span class="pill__grain" aria-hidden="true"></span>
<span class="pill__light" data-light aria-hidden="true"></span>
<button class="add" type="button" data-add data-autoclic aria-pressed="false">
<span class="closed" data-closed>
<svg class="plus" data-plus viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5.5v13M5.5 12h13"></path></svg>
<span class="closed__word" data-label>Add to playlist</span>
</span>
<span class="open" data-open aria-hidden="true">
<span class="stack" data-stack>
<span class="sc sc--1" data-sc><span class="art art--tide"></span></span>
<span class="sc sc--2" data-sc><span class="art art--ember"></span></span>
<span class="sc sc--3" data-sc><span class="art art--bloom"></span></span>
<span class="sc sc--top" data-sctop><span class="art art--harbour"></span></span>
</span>
<span class="lines">
<span class="line1">
<svg class="check" data-checkic viewBox="0 0 24 24"><path data-check d="M5.5 12.6 10 17 18.5 7.6"></path></svg>
<span class="roll" data-roll>
<span class="roll__item" data-r1>Night Drive</span>
<span class="roll__item" data-r2>Added to Night Drive</span>
</span>
</span>
<span class="line2"><span class="num" data-num></span><span class="unit" data-unit>songs</span></span>
</span>
</span>
</button>
</div>
<span class="pill__edge" aria-hidden="true"></span>
</div>
<!-- the cover in flight: it lives in the wrap, above the row and the pill -->
<span class="flyer" data-flyer aria-hidden="true"><span class="art art--harbour"></span><span class="flyer__sheen"></span></span>
<p class="sr" data-live aria-live="polite"></p>
</div>
<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>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.
24 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 “Add to playlist button” from Animorio and fit it into my siteInside the pill a layer with overflow hidden holds the closed content (the plus and Add to playlist) and the open one (the stack and the two lines), both absolutely positioned from the left. Both widths are measured on the real words and GSAP only changes the pill’s width: elastic.out to open, back.out to close, and the open content is uncovered from the left.
Each cover is a class with three or four layered gradients (the sun is a radial-gradient cut by the background size, the sea a repeating-linear-gradient). So the flying copy is just another element with the same class, with no images and no duplicate ids.
A tween takes t from 0 to 1 and on every frame the flying cover is placed on a quadratic curve between its socket in the row and the spot on top of the stack, with the control point ARC pixels above the higher of the two. Both positions are read again on every frame with getBoundingClientRect, so the flight stays right even while the pill is still widening or the window is resized. Meanwhile the scale goes from 48 to 30 pixels and the rotation makes a half turn.
On landing the copy disappears and the real cover shows on top of the stack. The stack takes scaleY SQUASH with its origin at the bottom in 80 ms and comes back with elastic.out; the covers below sink two pixels in a cascade from the top, the pill scales to 1.018 and an amber radial light crosses it.
The number is one digit per cell, each a grid with overflow hidden: only the digits that change roll, the new one comes in from below with back.out and the old one leaves at the top. Taking the song out rolls them the other way.
Two quickTo calls move the cover’s rotationX and rotationY toward the pointer (up to TILT degrees, inside a socket with perspective) and a soft-light radial highlight moves the same way. The drawn pointer of the autopilot does the same: on every frame it passes its position to the same function.
| Name | File | Default | What it changes |
|---|---|---|---|
LABEL | script.js | Add to playlist | The label of the closed button. |
PLAYLIST | script.js | Night Drive | The playlist’s name, written after Added to. |
COUNT | script.js | 23 | How many songs the playlist has before adding. |
ACCENT | script.js | #ffb04a | The colour of the check, the count and the light. |
FLIGHT | script.js | 0.8 | How many seconds the cover’s flight lasts. |
ARC | script.js | 56 | How many pixels the cover rises above its row before dropping. |
SQUASH | script.js | 0.84 | How much the stack squashes when the cover lands on it (1 = not at all). |
TILT | script.js | 9 | How many degrees the cover tilts toward the pointer. |
HOLD | script.js | 2.2 | How many seconds the song stays added in the autopilot before it is taken out. |
In music, podcast or audiobook apps and sites, to add a song to a collection; it also works to save a product to a list or a photo to an album, where the stack shows where the thing went.
On the phone the gesture is the same with touch; the tilt toward the pointer is there only with a mouse. The row and the pill narrow with the screen and the flight is computed again on the real positions.
With reduced motion nothing flies, tilts or rolls: the cover fades out of the row and fades in on top of the stack, the pill changes size while its content is hidden and the words change with a fade.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 9.0 KB; the libraries: GSAP 28 KB.
Tested on 13 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.