Skip to content
animorio
IT
All components

Compare button

Buttons, HoverGSAP, CSS onlyMediumCompressed weight: Demo 9.4 KBGSAP 28 KBFreeDownload the zip

The Compare button on the product card of a made-up bike shop, premium on black: on click the bike's thumbnail leaves the pill and flies on an arc into the compare bar rising from below, the button turns into “Added · 2 of 3” with a drawn check and the bar shows Compare now; a second click flies it back, and with the bar full the button dims into Compare list full.

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>
<!--
  "Compare 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 Compare button with the thumbnail that flies into the bar</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 Compare button of a made-up bike shop's product card: pressed, the small thumbnail of the bike leaves the
         pill and flies on an arc into the compare bar that rises from below; a second press takes it back -->
    <svg width="0" height="0" style="position:absolute" aria-hidden="true">
      <symbol id="bike" viewBox="0 0 32 32">
        <circle cx="9" cy="20" r="5.6"></circle>
        <circle cx="23" cy="20" r="5.6"></circle>
        <path d="M9 20 13.6 12.4h8.2L23 20M13.6 12.4 16.4 20h-7.4M16.4 20l5.4-7.6M12.4 10h3.2M20.2 9.6h2.8l-1.2 2.8"></path>
      </symbol>
    </svg>

    <div class="wrap" data-wrap>
      <div class="pill" data-pill>
        <span class="pill__floor" aria-hidden="true"></span>
        <div class="pill__clip">
          <span class="pill__grain" aria-hidden="true"></span>
          <span class="pill__sheen" aria-hidden="true"></span>
          <button class="cmp" type="button" data-cmp aria-pressed="false" aria-label="Add Velomar Arc 2 to compare">
            <span class="socket" data-socket aria-hidden="true">
              <span class="tile tile--arc" data-thumb><svg><use href="#bike"></use></svg><span class="tile__gloss"></span></span>
            </span>
            <span class="label"><span class="label__in" data-label>Compare</span></span>
            <span class="ic" aria-hidden="true">
              <svg viewBox="0 0 24 24">
                <g class="ic__cmp" data-iccmp><rect x="3.6" y="5.2" width="6.8" height="13.6" rx="1.8"></rect><rect x="13.6" y="5.2" width="6.8" height="13.6" rx="1.8"></rect><path d="M6 9.2h2M16 9.2h2M6 12h2M16 12h2"></path></g>
                <circle class="ic__ring" data-icring cx="12" cy="12" r="8.6"></circle>
                <path class="ic__check" data-iccheck d="M7.8 12.4 10.8 15.3 16.4 9.2"></path>
                <path class="ic__full" data-icfull d="M6.2 17.8 17.8 6.2"></path>
              </svg>
            </span>
          </button>
        </div>
        <span class="pill__edge" aria-hidden="true"></span>
      </div>

      <div class="bar" data-bar role="region" aria-label="Compare list">
        <span class="bar__edge" aria-hidden="true"></span>
        <div class="slots">
          <button class="slot" type="button" data-slot="0" aria-label="Empty slot, add a bike"><span class="slot__plus" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M12 7v10M7 12h10"></path></svg></span><span class="slot__ring" aria-hidden="true"></span></button>
          <button class="slot" type="button" data-slot="1" aria-label="Empty slot, add a bike"><span class="slot__plus" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M12 7v10M7 12h10"></path></svg></span><span class="slot__ring" aria-hidden="true"></span></button>
          <button class="slot" type="button" data-slot="2" aria-label="Empty slot, add a bike"><span class="slot__plus" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M12 7v10M7 12h10"></path></svg></span><span class="slot__ring" aria-hidden="true"></span></button>
        </div>
        <div class="cta">
          <span class="cta__hint" data-hint>Add 1 more</span>
          <a class="go" href="#compare" data-go>
            <span class="go__word">Compare now</span>
            <svg class="go__arrow" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h13M13 7l5 5-5 5"></path></svg>
          </a>
        </div>
      </div>
      <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>

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.

20 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 “Compare 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

On a black background there is a dark pill sixty pixels tall, its body fading from charcoal to near black, a very fine grain, a one pixel edge catching the light along the top and soft shadows with a faint orange glow: on the left, in a round recess, the bike’s thumbnail, a glossy orange tile with a bike drawn in line; then the word Compare and the two columns icon. On hover the pill lifts by a pixel, the edge light follows the pointer and the thumbnail gives a little nod; pressed, it gives by a pixel and springs back. On click the compare bar rises from below with a bounce, with its three slots (another bike already waits in the first) and the empty ones showing a plus; the thumbnail leaves the recess, which keeps a dashed circle, and flies on an arc over the pill, turning slightly, growing a little and changing from a circle to a rounded square, into the second slot. The slot catches it with a squash and lights up with an orange halo, the bar jolts by a pixel, Compare now comes in with its arrow snapping, and the button’s words roll into Added · 2 of 3 while the icon turns away and the circle and check draw themselves. If another bike is added to an empty slot, only the number rolls in the button. A second click flies the thumbnail back to its recess along the same arc reversed, and it lands with a sway. When the three slots are full of other bikes the button dims to grey with Compare list full, the thumbnail turns grey and a stroke crosses the icon; pressed, it shakes its head and the slots flash. Tapping a bike in the bar takes it out. A drawn pointer shows the whole loop on its own and repeats.

How it works

The arc flight that chases its target

The flying thumbnail is a copy of the tile fixed to the window. A single tween moves a variable p from 0 to 1, and every frame reads the rectangles of the recess and the slot again: x and y follow an in-out ease, the height loses ARC_HEIGHT times sin(πp), while size, corner radius and rotation move from one shape to the other. So the flight lands right even while the bar is still rising or the window changes size.

The pill that changes words

The pill’s width is measured on a hidden clone of the label in the same typeface: GSAP moves it with back.out while the old words leave upwards and the new ones come in from below. When only the slot count changes, only the number rolls, in tabular figures.

The drawn check and stroke

The icon has four SVG parts: the two columns, the ring, the check and the full state stroke. Ring, check and stroke draw themselves with stroke-dashoffset, the columns turn away and shrink.

The list decides everything

An array of three slots says who is in; from it come the button state (Compare, Added, Compare list full), the words in the bar (Add 1 more or Compare now) and the bar itself, which rises when our bike is in or there are at least two.

Values to change

NameFileDefaultWhat it changes
LABELscript.jsCompareThe label of the button at rest.
ADDEDscript.jsAddedThe word of the added state, before the slot count.
FULL_LABELscript.jsCompare list fullThe label of the dimmed button when the bar is full.
ACCENTscript.js#ff8a4cThe colour of the check, the slot glow and Compare now.
FLIGHTscript.js0.75How many seconds the thumbnail’s flight lasts.
ARC_HEIGHTscript.js64How high the flight’s arc rises, in pixels.
SPRINGscript.js0.6How long the spring that changes the pill’s width lasts, in seconds.

Try them in the Playground

When to use it

On the product cards of a bike, electronics, phone or appliance shop, in an e-commerce results grid, in plan listings: wherever people pick two or three things to put side by side.

On phones

The bar narrows to the screen width minus thirty-two pixels, under 360 the slots go down to 40 pixels and Compare now gets narrower; a finger presses like the mouse and taps bikes in the bar to take them out. Without hover the edge light stays still in the middle.

With reduced motion

No flight or springs: the thumbnail fades out of the recess and into the slot, the bar fades in and out in place, the words cross-fade and the check arrives already drawn.

Pitfalls

  • The flying copy had its left and top cancelled by an inset: auto placed after them, and with position fixed it ended up in its static position, below the bottom of the page: the flight happened but could not be seen. Now it has left 0, top 0, right and bottom auto, and only GSAP moves it.
  • On the first click the bar rises while the thumbnail takes off: computing the landing once made the thumbnail land below the slot. The flight reads the rectangles again every frame.
  • The pill’s width is measured on the real words in a hidden clone, and again once the typeface arrives and on resize.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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