Skip to content
animorio
IT
Back to the library

Shift swap

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

Swapping a shift with a colleague in a rota app: pick who with, their shift drops into the place on the right, and “Ask to swap” sends the request. While it waits the two shifts lift a little off their places; on approval they cross, one over and one under, and land swapped while the week’s hours roll. “Undo swap” brings them 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>
<!--
  "Shift swap" 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>Shift swap</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">
    <!-- swapping a shift with a colleague in a rota app: pick who, ask, and when they approve the two
         shifts cross and land in each other's place while the week's hours roll -->
    <section class="sw" data-sw aria-labelledby="sw-title">
      <header class="sw__head">
        <h1 id="sw-title">Swap a shift</h1>
        <p class="sw__hours"><span>Your week</span><b data-hours>38 h</b></p>
      </header>

      <div class="sw__pair">
        <div class="sw__slot is-you" data-slot-a>
          <p class="sw__who"><i class="sw__face" aria-hidden="true">Y</i><span>You</span></p>
          <div class="sw__frame">
            <article class="tk" data-ticket-a>
              <div class="tk__in">
                <i class="tk__bar" aria-hidden="true"></i>
                <b class="tk__day">Sat 28</b>
                <span class="tk__time">07:00 – 15:00</span>
                <em class="tk__tag">Morning · 8 h</em>
              </div>
            </article>
          </div>
        </div>
        <span class="sw__turn" data-turn aria-hidden="true"><svg viewBox="0 0 20 20"><path d="M4.500 7.500h10.500l-3-3M15.500 12.500H5l3 3"></path></svg></span>
        <div class="sw__slot" data-slot-b>
          <p class="sw__who"><i class="sw__face" aria-hidden="true" data-face>N</i><span class="sw__roll"><span data-name>Nora</span></span></p>
          <div class="sw__frame">
            <article class="tk" data-ticket-b>
              <div class="tk__in" data-in-b>
                <i class="tk__bar" aria-hidden="true"></i>
                <b class="tk__day" data-day>Sun 29</b>
                <span class="tk__time" data-time>15:00 – 21:00</span>
                <em class="tk__tag" data-tag>Evening · 6 h</em>
              </div>
            </article>
          </div>
        </div>
      </div>

      <div class="sw__with" role="radiogroup" aria-label="Swap with" data-with>
        <i class="sw__pick" data-pick aria-hidden="true"></i>
        <button class="sw__chip" type="button" role="radio" aria-checked="true" data-chip>Nora</button>
        <button class="sw__chip" type="button" role="radio" aria-checked="false" tabindex="-1" data-chip>Idris</button>
        <button class="sw__chip" type="button" role="radio" aria-checked="false" tabindex="-1" data-chip>Mei</button>
      </div>

      <p class="sw__say" aria-live="polite"><span data-say>You’d work Sun 29, 15:00 – 21:00</span></p>

      <button class="sw__go" type="button" data-go>
        <i class="sw__bar" data-bar aria-hidden="true"></i>
        <span class="sw__gotext"><span data-golabel>Ask Nora to swap</span></span>
      </button>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></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.

32 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 “Shift swap” 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 near black, a dark card: “Swap a shift” and on the right “Your week 38 h”. Two places side by side: on the left “You” with the shift “Sat 28, 07:00 – 15:00, Morning · 8 h”, in the place with the dashed violet edge; on the right the colleague, “Nora”, with “Sun 29, 15:00 – 21:00, Evening · 6 h”; between them a circle with two arrows. Below, three names in a row (Nora, Idris, Mei) with the pill sliding onto the chosen one: change colleague and the shift on the right drops and comes back with its own times, and the line below says what you would work. Press “Ask Mei to swap” and the button dims into “Waiting for Mei” with a violet line advancing, and the two shifts lift a little, showing the empty places. On approval they take a small run-up and cross: yours goes over, rising and leaning, the other under, smaller; the circle with the arrows makes half a turn and the hours roll from 38 to 35. They land a pixel too far and settle; the line says “Mei approved. You work Sun 29” and the button becomes “Undo swap”, which does it all in reverse.

How it works

The swap is one number

k goes from 0 (each in its place) to 1 (swapped). One function works out the pose of both shifts from it: x is the distance between the places times k, y and tilt follow the sine of k, so half way they are at their most and on arrival at zero.

Over and under

Your shift rises LIFT pixels and grows 5%, the other drops and shrinks: with a fixed z-index it really seems to pass underneath.

The wait

The request takes k to 0.1 (the shifts lift a little) and runs a line along the bottom of the button for WAIT seconds; then a single tween takes k to 1 with an ease that takes a run-up and goes slightly past the arrival.

The hours travel with k

The week’s hours sit in the same object and the same tween: on undo they come back together with the shifts.

The colleague

Three buttons in a radiogroup with the keyboard arrows; the pill moves in percent, so there is nothing to measure again, and the content of the shift on the right leaves and comes back.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#8b7bffThe colour of your place, of the request and of the finished swap.
WAITscript.js1.4The seconds of waiting before the colleague approves.
CROSSscript.js0.9How long the two shifts take to cross.
LIFTscript.js26How many pixels the shifts rise and drop while crossing.
TILTscript.js6How many degrees they lean half way.
HOURSscript.js38Your hours for the week before the swap.
LOOPscript.jstrueLeft alone, the demo’s pointer picks a colleague, asks for the swap and then undoes it.

Try them in the Playground

When to use it

In the rota app of a bar, a shop, a hospital or a warehouse, and in workforce tools: when someone cannot work a shift and offers it to a colleague, with approval before it really changes.

On phones

The same card, as wide as the screen minus the margins: the two places stay side by side (the distance is measured again on every width change), under 340 pixels day and time tighten a little, and names and button are 28 and 44 pixels tall.

With reduced motion

The shifts do not fly: they fade out and back in already swapped; the colleague’s pill and the words change in one step and the hours go straight to the new number. The demo does not move by itself.

Pitfalls

  • People, shifts and hours are made up and no request is sent: in a real app approval comes from the colleague (or the manager) and can also be a no.
  • The pose of the shifts is written by hand in the style, from one number: GSAP never touches their transform, or it would read it back and add it to its own.
  • The distance between the two places is in pixels: it is measured again on resize and the pose rewritten, even half way through a swap.
  • While the request waits or the shifts fly, the colleagues’ names are disabled: no changing colleague half way.
  • The demo’s pass waits for the shifts to really land before the next step: it stays in time even when wait and duration change.
  • The swap is not told by motion alone: the line below writes it and the button changes its name.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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