Skip to content
animorio
IT
All components

Swapping payment cards

Carts, HoverGSAP, CSS onlyMediumCompressed weight: Demo 10 KBGSAP 28 KBFreeDownload the zip

The payment step of a premium online shop, on black: a smoked glass panel with three real cards stacked as in a digital wallet (brushed graphite, copper, the indigo glass of a wallet) and the three rows to choose from below. Picking one, the two cards step aside, trade places and the new one lands in front on a spring; the glass pill slides onto the row, the card's colour spreads under the panel, and the light follows the pointer on the metal and along the edge. Pay works with a beam of light running round the button and ends on Payment complete.

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>
<!--
  "Swapping payment cards" 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 payment method with the cards that trade places</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" data-stage>
    <!-- the payment step of an online shop's checkout. Above, the wallet: the three ways to pay as real cards in a
         stack, the chosen one in front. Picking another row, the two cards step aside, trade places and the new one
         lands in front on a spring; the light on the metal follows the pointer -->
    <section class="pay" data-card aria-label="Payment method">
      <span class="pay__glow" data-glow aria-hidden="true"></span>
      <span class="pay__grain" aria-hidden="true"></span>

      <header class="pay__head">
        <h1 class="pay__title">Payment method</h1>
        <p class="pay__total"><span class="pay__total-label">Total</span><strong class="pay__total-sum" data-total>$248.00</strong></p>
      </header>

      <div class="wallet" data-wallet aria-hidden="true">
        <span class="wallet__floor" data-floor></span>

        <div class="cc" data-cc="graphite">
          <div class="cc__body" data-body>
            <div class="cc__face cc--graphite">
              <span class="cc__brand">Norvik</span>
              <svg class="cc__mark" viewBox="0 0 24 16"><path d="M2 14L9 2h4L6 14zM11 14l7-12h4l-7 12z"/></svg>
              <svg class="cc__chip" viewBox="0 0 30 22"><rect x="0.5" y="0.5" width="29" height="21" rx="4.5"/><path d="M0.5 8h9M0.5 14h9M20.5 8h9M20.5 14h9M9.5 0.5v21M20.5 0.5v21M9.5 11h11"/></svg>
              <svg class="cc__waves" viewBox="0 0 16 18"><path data-wave d="M3 5.2a5 5 0 0 1 0 7.6"/><path data-wave d="M6.6 3a8.2 8.2 0 0 1 0 12"/><path data-wave d="M10.2 1a11.4 11.4 0 0 1 0 16"/></svg>
              <span class="cc__holder">Mira Lane</span>
              <span class="cc__digits">4242</span>
              <span class="cc__sheen"></span>
            </div>
          </div>
          <span class="cc__dim" data-dim></span>
        </div>

        <div class="cc" data-cc="copper">
          <div class="cc__body" data-body>
            <div class="cc__face cc--copper">
              <span class="cc__brand">Aurel</span>
              <svg class="cc__mark" viewBox="0 0 24 16"><path d="M12 1.5l6.5 13h-13z"/></svg>
              <svg class="cc__chip" viewBox="0 0 30 22"><rect x="0.5" y="0.5" width="29" height="21" rx="4.5"/><path d="M0.5 8h9M0.5 14h9M20.5 8h9M20.5 14h9M9.5 0.5v21M20.5 0.5v21M9.5 11h11"/></svg>
              <svg class="cc__waves" viewBox="0 0 16 18"><path data-wave d="M3 5.2a5 5 0 0 1 0 7.6"/><path data-wave d="M6.6 3a8.2 8.2 0 0 1 0 12"/><path data-wave d="M10.2 1a11.4 11.4 0 0 1 0 16"/></svg>
              <span class="cc__holder">Mira Lane</span>
              <span class="cc__digits">0917</span>
              <span class="cc__sheen"></span>
            </div>
          </div>
          <span class="cc__dim" data-dim></span>
        </div>

        <div class="cc" data-cc="halo">
          <div class="cc__body" data-body>
            <div class="cc__face cc--halo">
              <span class="cc__brand">Halo Pay</span>
              <svg class="cc__mark" viewBox="0 0 24 16"><path d="M12 2.2a5.8 5.8 0 1 1 0 11.6a5.8 5.8 0 1 1 0-11.6zM12 5.4a2.6 2.6 0 1 0 0 5.2a2.6 2.6 0 1 0 0-5.2z" fill-rule="evenodd"/></svg>
              <svg class="cc__face-id" viewBox="0 0 24 24"><path d="M3 8V5.5A2.5 2.5 0 0 1 5.5 3H8M16 3h2.5A2.5 2.5 0 0 1 21 5.5V8M21 16v2.5a2.5 2.5 0 0 1-2.5 2.5H16M8 21H5.5A2.5 2.5 0 0 1 3 18.5V16M8.5 9v1.5M15.5 9v1.5M12 9v4.2h-1M9 16.2c1.8 1.3 4.2 1.3 6 0"/></svg>
              <svg class="cc__waves" viewBox="0 0 16 18"><path data-wave d="M3 5.2a5 5 0 0 1 0 7.6"/><path data-wave d="M6.6 3a8.2 8.2 0 0 1 0 12"/><path data-wave d="M10.2 1a11.4 11.4 0 0 1 0 16"/></svg>
              <span class="cc__holder">Mira Lane</span>
              <span class="cc__digits cc__digits--word">Wallet</span>
              <span class="cc__sheen"></span>
            </div>
          </div>
          <span class="cc__dim" data-dim></span>
        </div>
      </div>

      <div class="methods" role="radiogroup" aria-label="Pay with" data-methods>
        <span class="methods__pill" data-pill aria-hidden="true"></span>

        <button class="method" type="button" role="radio" aria-checked="true" data-method="graphite">
          <span class="method__thumb cc--graphite" aria-hidden="true"></span>
          <span class="method__text"><span class="method__name">Norvik Graphite</span><span class="method__sub">Ends in 4242 · 08/28</span></span>
          <span class="method__tick" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="tick__ring" cx="10" cy="10" r="8.5"/><circle class="tick__fill" data-fill cx="10" cy="10" r="9"/><path class="tick__check" data-check pathLength="1" d="M6.2 10.3l2.6 2.6 5-5.4"/></svg></span>
        </button>

        <button class="method" type="button" role="radio" aria-checked="false" data-method="copper">
          <span class="method__thumb cc--copper" aria-hidden="true"></span>
          <span class="method__text"><span class="method__name">Aurel Copper</span><span class="method__sub">Ends in 0917 · 02/27</span></span>
          <span class="method__tick" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="tick__ring" cx="10" cy="10" r="8.5"/><circle class="tick__fill" data-fill cx="10" cy="10" r="9"/><path class="tick__check" data-check pathLength="1" d="M6.2 10.3l2.6 2.6 5-5.4"/></svg></span>
        </button>

        <button class="method" type="button" role="radio" aria-checked="false" data-method="halo">
          <span class="method__thumb cc--halo" aria-hidden="true"></span>
          <span class="method__text"><span class="method__name">Halo Pay</span><span class="method__sub">Confirm with Face ID</span></span>
          <span class="method__tick" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="tick__ring" cx="10" cy="10" r="8.5"/><circle class="tick__fill" data-fill cx="10" cy="10" r="9"/><path class="tick__check" data-check pathLength="1" d="M6.2 10.3l2.6 2.6 5-5.4"/></svg></span>
        </button>
      </div>

      <button class="paybtn" type="button" data-pay>
        <span class="paybtn__beam" data-beam aria-hidden="true"></span>
        <span class="paybtn__face" data-payface>
          <span class="paybtn__label" data-label="idle">
            <svg class="paybtn__icon" viewBox="0 0 16 16" aria-hidden="true"><rect x="3.2" y="7" width="9.6" height="7" rx="1.8"/><path d="M5.4 7V5.2a2.6 2.6 0 0 1 5.2 0V7"/></svg>
            <span>Pay <span data-sum>$248.00</span></span>
          </span>
          <span class="paybtn__label" data-label="busy"><span class="paybtn__shimmer">Processing</span></span>
          <span class="paybtn__label" data-label="done">
            <svg class="paybtn__icon paybtn__icon--done" viewBox="0 0 16 16" aria-hidden="true"><path data-donecheck pathLength="1" d="M3.4 8.4l3 3 6.2-6.6"/></svg>
            <span>Payment complete</span>
          </span>
        </span>
      </button>
    </section>
    <p class="sr" aria-live="polite" data-live></p>
  </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.

43 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 “Swapping payment cards” 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 black sits the payment panel of an online shop: dark glass with a very fine grain, a one pixel edge that catches the light and a long shadow in the colour of the chosen card. At the top Payment method and the total, $248.00. Below it, the wallet: three real cards stacked, the chosen one in front and the other two peeking above, smaller and darker. Norvik Graphite is brushed graphite with a gold chip, Aurel Copper is copper with a warm light in its corner, Halo Pay is the indigo glass of a wallet with the Face ID mark; all of them carry the name Mira Lane, the last digits and the contactless waves. Further down the three rows, each with its card in miniature, its name, last digits and expiry, and a circle that fills with a check. Picking another row the two cards step aside, the old one to the left and the new one to the right, leaning a few degrees; halfway they trade places in depth and the new one lands in front on a spring that passes the mark and settles, while the old one goes back into the stack and darkens. The contactless waves light up one after the other, the glass pill slides onto the row with a small rubbery squeeze, and the card's colour spreads slowly under the wallet and into the panel's shadow. With the pointer the light follows it on a spring: a soft sheen runs over the metal of the front card, the card leans slightly toward it and the panel's edge lights up only at that point. Pay $248.00 with its padlock dips and comes back on an elastic, the label becomes a shimmering Processing and a beam of light runs twice round the button; then the button turns green with a check that draws itself and Payment complete, and the front card gives a small nod as if tapped on a reader. The walk on its own tries the copper, then the wallet, pays, goes back to the graphite and starts again; it also really works, with the mouse, touch and the keyboard arrows.

How it works

Three layers per card

Every card is .cc, moved by GSAP in the stack, holding .cc__body, tilted by GSAP toward the pointer, and inside that .cc__face, drawn by CSS: this way the stack's transform, the tilt and the materials never wipe each other out. The materials are layered gradients: one pixel repeating lines for the brushing, a radial light in the corner and a 135 degree gradient.

The stack

Place i in the stack is y = −i times a tenth of the height, scale 1 − 0.075·i and a dark veil at opacity 0.38·i. The order is a list: the chosen card goes to the head, the previous one right after it, and every zIndex comes from there.

The swap

A timeline takes the front card to the left and the chosen one to the right by a fifth of the width in 0.26 s, turning them four degrees in opposite directions. At the widest point a call resets the zIndex from the new order, then the chosen card comes back to the middle with back.out(1.7) and the others slide to their places in the stack with power3.out.

The light on a spring

The pointer (or the walk on its own, moving the target with GSAP) is the target of a spring integrated by hand, stiffness 120 and damping 15, with the step capped at 1/30 s. Every frame writes --mx and --my on the panel, which move the lit edge (a radial gradient with a mask that keeps only the edge's pixel), and --sx on the front card's sheen; the loop stops when the spring is still.

Pay and the beam

The beam is a conic-gradient just larger than the button, behind its face, turned by an --a variable that GSAP takes from 0 to 720 degrees. The three labels share one grid cell, leaving upwards and coming in from below; the check draws itself with pathLength 1 and stroke-dashoffset.

Values to change

NameFileDefaultWhat it changes
TOTALscript.js248The order total, in dollars.
SHUFFLEscript.js0.2How far the two cards step aside to trade places, as a share of the card's width.
LIFTscript.js4How much they turn while they step aside, in degrees.
SPRINGscript.js1.7How far the new card passes the mark landing in front.
TILTscript.js5How much the front card leans toward the pointer, in degrees.
PROCESSINGscript.js1.5How long the payment works before it is complete, in seconds.
SPEEDscript.js12 = the walk on its own twice as fast, 0.5 = half.
LOOPscript.jstrueRepeats the walk on its own.

Try them in the Playground

When to use it

For the checkout of a high end online shop, a fashion or design brand, a subscription app: the step where you choose what to pay with, when the saved cards should look like the customer's own cards.

On phones

The same animation with adapted sizes: the panel is almost as wide as the screen, the cards and the rows take their height from the window, and a finger picks the row and brings the light where it touches.

With reduced motion

The cards do not move: the stack changes order at once and the new card fades in, the pill fades out and back in on the row, the card does not tilt and the button's beam stays still; Pay's labels change with a fade.

Pitfalls

  • If the same card gets both the stack's transform and the tilt, the last one wipes out the first: that is why every card has three layers and GSAP moves two different ones.
  • Changing the zIndex at the start of the swap makes the new card pass through the old one: it has to change at the widest point, when the two hardly overlap any more.
  • A click during a swap left the cards halfway: before every new swap the previous one is taken to its end with progress(1).

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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