Skip to content
animorio
IT
Back to the library

Swinging price tag

Images, Hover, PhysicsGSAP, Canvas, CSS onlyMediumCompressed weight: Demo 10 KBGSAP 28 KBFreeDownload the zip

The page of a dress from Maison Ondine, a made-up boutique, with a real photo: the price tag hangs on a thin thread from a brass eyelet on the corner of the photo and swings like a real pendulum when you change size or colour, harder when the choice jumps further; the price rolls digit by digit, a new colour dyes only the fabric of the dress, and passing the mouse over the tag flicks it. Minimal style.

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>
<!--
  "Swinging price tag" 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>Maison Ondine, the Wren dress</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/fraunces@5.3.0/full.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/inter-tight@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- the product page of a made-up boutique, Maison Ondine, for one dress. A real photo of the dress; the price tag hangs
       from an eyelet on the corner of the photo by a thin thread and swings like a real pendulum when you change size or
       colour (or flick it with the pointer); the price on the tag rolls to the new value; a new colour recolours only the
       fabric of the dress in the photo -->
  <main class="scena">
    <article class="pezzo" data-pezzo>
      <figure class="foto" data-foto>
        <img class="foto__img" data-img src="abito.webp" alt="A navy dress with a small white floral print, the hands in front holding a pink blossom" width="960" height="665">
        <canvas class="foto__tinta" data-tinta aria-hidden="true"></canvas>
        <canvas class="foto__tinta" data-tinta aria-hidden="true"></canvas>
        <span class="foto__grana" aria-hidden="true"></span>
        <span class="foto__occhiello" data-occhiello aria-hidden="true"></span>
      </figure>

      <div class="appeso" data-appeso aria-hidden="true">
        <svg class="filo" data-filo viewBox="0 0 10 100" preserveAspectRatio="none"><line x1="5" y1="0" x2="5" y2="100"/></svg>
        <div class="ombra" data-ombra></div>
        <div class="cartellino" data-cartellino>
          <span class="cartellino__buco"></span>
          <span class="cartellino__marca">Maison Ondine</span>
          <span class="cartellino__riga"></span>
          <span class="cartellino__taglia" data-tag-taglia>S</span>
          <span class="cartellino__prezzo">
            <span class="valuta">$</span><span class="cifre" data-cifre></span>
          </span>
          <s class="cartellino__vecchio" data-vecchio>$168</s>
          <span class="cartellino__codice">WR 0412</span>
        </div>
      </div>

      <section class="pannello">
        <p class="marca">Maison Ondine</p>
        <h1 class="nome">The Wren dress</h1>
        <p class="nota">Washed cotton voile, cut on the bias, lined to the knee.</p>

        <div class="gruppo">
          <p class="etichetta">Colour <b data-colore-nome>Midnight</b></p>
          <div class="campioni" role="radiogroup" aria-label="Colour" data-campioni>
            <button class="campione" role="radio" aria-checked="true" aria-label="Midnight" data-colore="0" style="--c:#1d2748"><span></span></button>
            <button class="campione" role="radio" aria-checked="false" aria-label="Sage" data-colore="1" style="--c:#6f8a6a"><span></span></button>
            <button class="campione" role="radio" aria-checked="false" aria-label="Clay, on sale" data-colore="2" style="--c:#a4513f"><span></span></button>
          </div>
        </div>

        <div class="gruppo">
          <p class="etichetta">Size</p>
          <div class="taglie" role="radiogroup" aria-label="Size" data-taglie>
            <span class="taglie__pillola" data-pillola aria-hidden="true"></span>
            <button class="taglia" role="radio" aria-checked="false" data-taglia="0">XS</button>
            <button class="taglia" role="radio" aria-checked="true" data-taglia="1">S</button>
            <button class="taglia" role="radio" aria-checked="false" data-taglia="2">M</button>
            <button class="taglia" role="radio" aria-checked="false" data-taglia="3">L</button>
          </div>
        </div>

        <button class="borsa" data-borsa>
          <span class="borsa__fondo" aria-hidden="true"></span>
          <span class="borsa__testo" data-borsa-testo>Add to bag</span>
          <svg class="borsa__spunta" viewBox="0 0 16 16" aria-hidden="true"><path data-spunta d="M3.5 8.4 6.6 11.4 12.6 4.8" pathLength="1"/></svg>
        </button>
      </section>
    </article>
  </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.

34 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

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 “Swinging price tag” 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 warm paper, on the left the real photo of a midnight blue dress with a small white floral print, hands in front holding a pink blossom, in a rounded frame with a touch of grain. On the top right corner of the photo there is a brass eyelet, and from it, on a thin thread, hangs the price tag: an ivory card with a reinforced hole, dashed stitching, Maison Ondine in italics, the size and the price, $168. On the right the name The Wren dress in a wide serif, one line on the fabric, three colour swatches (Midnight, Sage, Clay) and the sizes XS, S, M, L in a bar with a light pill on the choice, then the black Add to bag pill. Changing size, the pill slides with a bounce, the tag takes a knock and swings, harder when the size jumps further, and the swings die away; the thread stretches a hair when it moves fast, the card lags a little behind and its shadow slides across the photo. The price rolls digit by digit to the new value: M costs 172, L 178. Changing colour, the fabric of the dress fades to sage or clay while the hands and the background stay real; the clay is 20% off, with the price in red and the old one struck through. Passing the mouse over the tag flicks it with the pointer’s speed; a click sets it swinging; Add to bag presses in, says Added and draws its tick.

How it works

A real pendulum in the ticker

The tag is an angle and a speed: on every frame of gsap.ticker, in four small steps, the acceleration is −k · sin(angle) − damping · speed, with k dropping as the thread gets longer, like a real pendulum. A change adds speed (the knock), and physics does the rest.

The thread that stretches and the card that lags

The whole group turns around the eyelet. The thread stretches a hair with the square of the speed and the card drops with it; the card also turns slightly against the speed, so it looks hung and not glued. The shadow slides the other way and spreads when the tag swings out.

The rolling price

Each digit is a column from 0 to 9 inside a window one digit tall: to reach the new number the column moves by yPercent −10 per unit, with power3.out and a small delay from right to left.

The fabric dyed on a canvas

On load the photo is copied onto a canvas and for each pixel we work out how much of it is blue fabric (a hue between cyan and violet, or an almost black blue). For Sage and Clay only that part is moved to the new hue, lighter and less saturated, once; then the two canvases over the photo fade in and out.

Sizes and the tour

The eyelet’s point and the thread length are measured again on resize. When nobody touches the page a timeline changes sizes and colours, flicks the tag and adds to the bag; the first touch stops it and it starts again after seven quiet seconds.

Values to change

NameFileDefaultWhat it changes
DAMPINGscript.js1.5How quickly the swing dies away, per second (higher stops sooner).
KICKscript.js1How hard a change of size or colour knocks the tag.
THREADscript.js1How long the thread is: 1.5 is half as long again, and swings slower.
PUSHscript.js1How much the pointer flicks the tag when it passes over it.
MAX_SWINGscript.js22The widest swing, in degrees.
ROLLscript.js0.9Seconds the price takes to roll to the new value.
FADEscript.js0.7Seconds the photo takes to change colour.
AUTOPLAYscript.js11: the page changes size and colour by itself when nobody touches it; 0: never.

Try them in the Playground

When to use it

For the product page of a shop with character: a boutique, a tailor, a vintage or craft shop. When the price changes with size or colour and the change should be felt, with a small physical gesture instead of a number that jumps.

On phones

The same animation with adapted sizes: the photo on top, as wide as the screen and measured on the height too, the eyelet further in so the tag swings without leaving the screen, a shorter tag and thread; below, the name, the colours, the sizes and the pill. Tapping the tag sets it swinging.

With reduced motion

The tag stays still and straight, the price changes with a fade instead of rolling, the photo changes colour with a fade and the text arrives without moving.

Pitfalls

  • A tween is not a pendulum: an elastic yoyo always has the same rhythm and the same number of bounces. Integrated in the ticker, a knock adds to whatever is already there, and a change halfway through a swing pushes it or brakes it as in real life.
  • Recolouring the whole photo with hue-rotate changes the hands and the background too, and looks fake at once: only the fabric is dyed, pixel by pixel, once on load.
  • The tag sticks out of the photo’s corner: on the phone the eyelet moves further in, or the swing would carry it off the screen.
  • GSAP rounds pixel values read from CSS: without autoRound turned off the tick drawn with pathLength 1 would appear all at once.

Libraries

GSAP 3.15.0, Fraunces (font variabile) 5.3.0, Inter Tight (font variabile) 5.3.0.

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

Testing

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