Skip to content
animorio
IT
All components

Fabric swatches button

Buttons, Hover, TransitionsGSAP, CSS onlyMediumCompressed weight: Demo 8.2 KBGSAP 28 KBFreeDownload the zip

The Order free swatches button of a made-up furniture studio, Fenn & Ode, for people who want to touch the fabric before buying the sofa. A dark pill on black, with the bouclé swatch in the well on the left and Free on the right. On the tap three fabrics are cut one after the other in the well: the square arrives, the zigzag of the pinking shears draws itself around it while the edge turns to teeth and a couple of thread crumbs fall, then the swatch is tossed in an arc over the label and lands in the tray on the right. A hairline under the pill fills a third for every swatch. With three in the tray they settle in a stack, a green tick draws itself in the well, a light crosses the pill and the label says when they arrive.

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>
<!--
  "Fabric swatches 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 Order free swatches button with the fabrics pinked and tossed into the pill</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 button of a made-up furniture studio, Fenn & Ode: pressed, each fabric is cut in the well with pinking
         shears, its zigzag edge drawing itself, then tossed over the label into the tray on the right; with three in
         the tray the swatches settle in a stack, a tick draws itself and the label says when they arrive -->
    <div class="wrap" data-wrap>
      <button class="sw" type="button" data-sw data-autoclic>
        <span class="sw__body" aria-hidden="true"><span class="sw__light" data-light></span><span class="sw__sweep" data-sweep></span></span>
        <span class="sw__edge" aria-hidden="true"></span>
        <span class="sw__line" aria-hidden="true"><span data-progress></span></span>

        <span class="well" aria-hidden="true">
          <span class="well__cut" data-cut>
            <span class="fab" data-fab></span>
            <svg class="well__svg" viewBox="0 0 30 30"><path class="well__zig" data-zig pathLength="1" d=""></path></svg>
          </span>
          <svg class="well__done" viewBox="0 0 24 24"><path class="well__tick" data-tick pathLength="1" d="M7.4 12.4 10.6 15.5 16.8 8.7"></path></svg>
        </span>

        <span class="label">
          <span class="label__main"><span data-word>Order free swatches</span></span>
          <span class="label__sub"><span data-sub>Up to 3 fabrics · posted free</span></span>
        </span>

        <span class="tray" data-tray aria-hidden="true">
          <span class="tray__free" data-free>Free</span>
        </span>
      </button>
      <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.

21 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 “Fabric swatches 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 ground sits a dark pill with the fine weave of a heavy cotton and a one-pixel edge catching light at the top. On the left, in a round well, an oat bouclé swatch already pinked; in the middle «Order free swatches» and «Up to 3 fabrics · posted free»; on the right Free in brass. On hover a warm light follows the pointer, the pill rises a pixel and the swatch straightens on a spring; pressed, it squashes slightly. On the tap Free lifts away, the label rolls to «Cutting swatches» and for each fabric (oat bouclé, sage linen, rust velvet) the square comes into the well a pixel too far, the white zigzag runs around it while the edge is cut to teeth and the swatch turns a little, four thread crumbs of its colour fall, then the swatch jumps in an arc over the label spinning and lands in the tray squashing like cloth, with the others shifting a hair. Under the pill a brass hairline grows a third for every swatch. At the end the three swatches settle in a stack, a green tick draws itself in the well, a green light crosses the pill, which swells a hair, the edge and the glow turn green and the label rolls to «Swatches on the way» and «Arrives Thu 19 Nov · free»; then everything goes back to rest.

How it works

The pinked edge

A function builds the points of a square whose sides are broken into teeth: the odd points step in by an amplitude. At zero amplitude it is a straight square with the same points, so GSAP takes the amplitude from 0 to 7.5 and the percentage clip-path is rebuilt every frame: the edge is cut while you watch.

The zigzag of the shears

The same zigzag, in SVG coordinates, becomes a path with pathLength 1: stroke-dashoffset goes from 1 to 0 in the same time as the cut, with autoRound off so GSAP does not round the line into jumps.

The arc toss

A copy of the swatch is born above the button, where the well is: x slides evenly to its place in the tray, y rises with power2.out and falls with power2.in, and meanwhile the swatch spins once and shrinks to 22 pixels. Positions are read at the moment of the toss, so they work at any width.

The cloth landing

In the tray the new swatch starts squashed (scaleX 1.12, scaleY 0.84) from its bottom edge and comes back on an elastic spring; the tray drops a pixel and a half and the swatches already there shift a hair.

The rolling lines

Label and small line sit in one-line windows: the new text comes in from below, the old one leaves at the top with the same curve and duration, so they never overlap, and it is removed when it has left.

Values to change

NameFileDefaultWhat it changes
LABELscript.jsOrder free swatchesThe label of the button at rest.
SUBscript.jsUp to 3 fabrics · posted freeThe small line under the label.
DONE_LABELscript.jsSwatches on the wayThe label when the swatches are ready.
ARRIVESscript.jsArrives Thu 19 Nov · freeWhen the swatches arrive.
TEETHscript.js5How many teeth the zigzag has on each side of the swatch.
CUTscript.js0.45The seconds of each cut.
SPRINGscript.js1How much the swatches bounce when they land.
HOLDscript.js2.6The seconds of the confirmation before going back to rest.
--brassstyle.css#d9b27cThe brass of Free, of the hairline and of the glow while cutting.
--donestyle.css#a6cf9bThe green of the tick and the confirmation.

Try them in the Playground

When to use it

On the page of a sofa, a curtain or an armchair, for a furniture shop, an upholsterer or an interior studio: ordering free fabric swatches before choosing. It also works for samples of wallpaper, leather, yarn or paint.

On phones

The pill takes the screen width minus the margins and lines shorten with an ellipsis if needed; the toss reads positions at the moment, so the arc always reaches the tray. Without hover the light stays off, the tap does everything.

With reduced motion

No tosses, springs or crumbs: each fabric fades into the well already pinked with the zigzag drawn, then appears in the tray; the hairline still fills, the tick appears already drawn and the labels change with a fade.

Pitfalls

  • The two rolling lines had different curves (power2.in for the leaving one, power3.out for the coming one) and overlapped halfway: same curve and same duration, and they always stay one under the other.
  • With «Cutting your swatches» the label touched the tray in the phone box and the arrival line was cut with an ellipsis: shorter labels.
  • The pinked clip-path needs the same number of points even with a straight edge, or the cut cannot be animated: the starting square is made of the same points at zero amplitude.
  • The zigzag drawn with stroke-dashoffset needs autoRound off (the empty plugin at the top of the script), or the line moves in jumps.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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