Skip to content
animorio
IT
All components

Add to bundle button

Buttons, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 5.1 KBGSAP 28 KBFreeDownload the zip

A light pill button for the page of a product you can buy in a set: inside it has a small tray with what is already in the bundle and the discount reached. Pressed, the two squares of the sign slide over each other on a spring, this product’s tile drops into the tray pushing the other aside, the discount rolls from −5% to −10% and the label says ‘In your bundle’; pressed again, the tile leaves and everything goes back.

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>
<!--
  "Add to bundle 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>Add to bundle button with the tile that drops into the tray and the discount that climbs</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">
    <!-- an add-to-bundle button for a product page: the pill holds a small tray with what is already in the bundle
         and the discount earned so far; pressed, the two squares of the sign slide over each other on a spring, this
         product's tile drops into the tray pushing the other aside, the discount rolls up and the label says it is
         in; pressed again, the tile leaves and everything goes back -->
    <button class="cmp" type="button" data-cmp aria-pressed="false">
      <span class="cmp__body" aria-hidden="true"><span class="cmp__wash" data-wash></span><span class="cmp__light"></span></span>

      <span class="sign" data-sign aria-hidden="true">
        <svg viewBox="0 0 24 24">
          <rect data-bar="a" x="2.6" y="6.5" width="9" height="11" rx="2.6"></rect>
          <rect data-bar="b" x="12.4" y="6.5" width="9" height="11" rx="2.6"></rect>
        </svg>
      </span>

      <span class="label"><span class="label__word" data-word>Add to bundle</span></span>

      <span class="tray" data-tray aria-hidden="true">
        <span class="tile tile--new" data-new><i></i></span>
        <span class="tile tile--old"><i></i></span>
        <span class="tray__count"><span data-count>5%</span></span>
      </span>
    </button>
    <p class="sr" data-live aria-live="polite"></p>

    <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.

15 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 “Add to bundle button” 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

In the middle, on white, a light pill 60 pixels tall with a soft shadow: on the left, in a dark round seat, two rounded squares side by side (the bundle sign), then the label ‘Add to bundle’ and, on the right, an inset tray with the tile of a product already chosen and the discount reached, −5%. The pointer arrives, the pill lifts by a pixel and a faint orange shade follows it; on press it squeezes and comes back on a spring. On click the two squares slide over each other with a bounce and the front one turns orange, room opens in the tray and this product’s orange tile drops into it with half a spin, the discount rolls to −10% and takes colour, the label rolls to ‘In your bundle’, the pill’s edge takes the orange and a warm veil stays on the sign’s side. A second click removes the product: the tile shrinks and falls away, the room closes, the discount goes back to −5%, the squares part. Left alone, a pointer adds it, waits and takes it out.

How it works

A real toggle

The button has aria-pressed and one function, set, that takes everything from one state to the other: the is-in class for edge, shadow and discount colour, the words, the sign, the tile.

The two squares that join

They are two SVG rects: GSAP animates the x attribute of both towards the centre with elastic.out, the second 50 milliseconds later. JOIN says how much they overlap.

The room, then the tile

The new tile starts zero wide: first it widens to 28 pixels with its margin, and the room pushes the other tile by itself; 60 milliseconds later the tile scales from 0.3 to 1, rotates from minus 40 degrees to zero and drops 10 pixels, all on a spring.

The discount and the label

The discount is STEP times the number of products in the bundle. Number and label leave upwards and the new version comes in from below when adding; the other way round when removing, so the direction says what happened.

Values to change

NameFileDefaultWhat it changes
IDLEscript.jsAdd to bundleThe label at rest.
ADDEDscript.jsIn your bundleThe label when the product is in the bundle.
OTHERSscript.js1How many products are already in the bundle.
STEPscript.js5How many discount points each product is worth.
ACCENTscript.js#ff6a3dThe colour of the product coming in, the edge and the discount.
SPRINGscript.js0.8How long the spring of the tile coming in lasts, in seconds.
JOINscript.js0.6How much the sign’s two squares overlap: 0 not at all, 1 one on the other.
HOLDscript.js2.4By itself: how many seconds it stays in the bundle before leaving.
LOOPscript.jstrueLeft alone, a pointer tries it by itself.

Try them in the Playground

When to use it

For the product page of an online shop that sells sets to build: skincare, coffee, supplements, accessories. The button shows at once what is already in the bundle and how much discount has been reached, without opening the cart.

On phones

The same button: the pill takes at most the screen width minus the margins and the long label is cut with an ellipsis. On touch there is no shade following the pointer.

With reduced motion

No springs and no spin: the tile fades in already in place, the squares move at once, discount and label change with a fade.

Pitfalls

  • The new tile has overflow hidden and zero width at rest: its rotation shows only because the room opens 60 milliseconds before it comes in.
  • The discount’s minus sign is the real character (code 8722), written with String.fromCharCode: the keyboard hyphen is shorter and lower than the digits.
  • The longer label must fit the pill with the tray widened too: try ADDED on a phone, where it is cut with an ellipsis.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 14 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