Skip to content
animorio
IT
Back to the library

Cart drawer

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

The page of a made-up home goods shop, Wren & Loom, with three products as tiles of colour: Add to bag pulls the cart out from the right like a drawer, the page dims and steps back a breath, the new line comes in at the top with a settle while the others move down, the count on the bag and the subtotal roll and the free shipping bar fills up to Free shipping unlocked, with a tick drawing itself and a thread of light. Remove slides a line away. 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 tab holds the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Cart drawer" 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>Bag, Wren &amp; Loom</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>
  <!-- the page of a made-up home goods shop, Wren & Loom: three products as tiles of colour with their name and price.
       Add to bag pulls the bag out from the right like a drawer: the page dims and steps back, the new line comes in at
       the top while the others move down, the count on the bag rolls, the subtotal rolls and the free shipping bar
       fills; at the goal a tick draws itself and a thread of light runs along the bar. Close with the button, Esc or a
       click outside -->
  <div class="pagina" data-pagina>
    <header class="testa">
      <span class="marchio">Wren &amp; Loom</span>
      <nav class="voci" aria-label="Shop">
        <a href="#" data-finto>Living</a>
        <a href="#" data-finto>Kitchen</a>
        <a href="#" data-finto>Bath</a>
      </nav>
      <button class="borsa" type="button" aria-label="Open bag, 0 items" data-apri>
        <svg viewBox="0 0 24 24" aria-hidden="true"><path class="borsa__corpo" d="M5.2 8.2h13.6l-1 11.1a1.6 1.6 0 0 1-1.6 1.5H7.8a1.6 1.6 0 0 1-1.6-1.5z"/><path class="borsa__manico" d="M8.8 8.2V7a3.2 3.2 0 0 1 6.4 0v1.2"/></svg>
        <span class="borsa__conto" aria-hidden="true"><span class="rullo" data-conto></span></span>
      </button>
    </header>

    <main class="vetrina">
      <p class="sopra">New this week</p>
      <h1 class="titolo">Slow things for the home</h1>
      <ul class="prodotti">
        <li class="prodotto" data-prodotto="throw" data-nome="Linen throw" data-variante="Sage, 130 × 170" data-prezzo="68" style="--tinta: #a9b39c; --tinta-2: #8e9a81">
          <span class="tassello" aria-hidden="true"><span class="tassello__trama"></span></span>
          <span class="prodotto__riga"><span class="prodotto__nome">Linen throw</span><span class="prodotto__prezzo">$68</span></span>
          <button class="aggiungi" type="button" data-aggiungi>
            <span class="aggiungi__piu" aria-hidden="true"><svg viewBox="0 0 12 12"><path d="M6 2v8M2 6h8"/></svg></span>
            <span>Add<span class="aggiungi__resto"> to bag</span></span>
          </button>
        </li>
        <li class="prodotto" data-prodotto="mug" data-nome="Stoneware mug" data-variante="Clay, 340 ml" data-prezzo="24" style="--tinta: #c99a7e; --tinta-2: #b48266">
          <span class="tassello" aria-hidden="true"><span class="tassello__trama"></span></span>
          <span class="prodotto__riga"><span class="prodotto__nome">Stoneware mug</span><span class="prodotto__prezzo">$24</span></span>
          <button class="aggiungi" type="button" data-aggiungi>
            <span class="aggiungi__piu" aria-hidden="true"><svg viewBox="0 0 12 12"><path d="M6 2v8M2 6h8"/></svg></span>
            <span>Add<span class="aggiungi__resto"> to bag</span></span>
          </button>
        </li>
        <li class="prodotto" data-prodotto="candle" data-nome="Beeswax candle" data-variante="Honey, 40 h" data-prezzo="34" style="--tinta: #dcc28e; --tinta-2: #c9aa6e">
          <span class="tassello" aria-hidden="true"><span class="tassello__trama"></span></span>
          <span class="prodotto__riga"><span class="prodotto__nome">Beeswax candle</span><span class="prodotto__prezzo">$34</span></span>
          <button class="aggiungi" type="button" data-aggiungi>
            <span class="aggiungi__piu" aria-hidden="true"><svg viewBox="0 0 12 12"><path d="M6 2v8M2 6h8"/></svg></span>
            <span>Add<span class="aggiungi__resto"> to bag</span></span>
          </button>
        </li>
      </ul>
    </main>
  </div>

  <div class="velo" data-velo aria-hidden="true"></div>

  <aside class="cassetto" role="dialog" aria-modal="true" aria-labelledby="titolo-borsa" aria-hidden="true" data-cassetto>
    <span class="cassetto__luce" aria-hidden="true"></span>
    <header class="cassetto__testa">
      <h2 id="titolo-borsa">Your bag <span class="cassetto__quanti"><span class="rullo" data-quanti></span></span></h2>
      <button class="chiudi" type="button" aria-label="Close bag" data-chiudi>
        <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8"/></svg>
      </button>
    </header>

    <section class="spedizione" data-spedizione>
      <p class="spedizione__frase">
        <span class="spedizione__finestra">
          <span class="spedizione__riga" data-frase>
            <span class="spedizione__manca"><span class="rullo" data-manca></span> away from free shipping</span>
            <span class="spedizione__fatta"><svg viewBox="0 0 16 16" aria-hidden="true"><path data-spunta-frase d="M3.6 8.4l2.9 2.9 5.9-6.2" pathLength="1"/></svg>Free shipping unlocked</span>
          </span>
        </span>
      </p>
      <span class="barra" data-barra>
        <span class="barra__pieno" data-pieno></span>
        <span class="barra__filo" data-filo></span>
        <span class="barra__meta" data-meta>
          <svg viewBox="0 0 16 16" aria-hidden="true"><circle class="barra__cerchio" cx="8" cy="8" r="6.6" pathLength="1" data-cerchio/><path class="barra__spunta" d="M5 8.3l2 2 4-4.3" pathLength="1" data-spunta/></svg>
        </span>
      </span>
    </section>

    <ul class="righe" data-righe aria-live="polite"></ul>
    <p class="vuoto" data-vuoto>Your bag is empty.<span>Free shipping on orders over $100.</span></p>

    <footer class="cassetto__piede">
      <p class="totale"><span>Subtotal</span><span class="totale__cifre rullo" data-totale></span></p>
      <p class="nota">Taxes and duties calculated at checkout.</p>
      <button class="cassa" type="button" data-cassa>
        <span class="cassa__luce" aria-hidden="true"></span>
        <span>Checkout</span>
        <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8h9M8.5 4.5L12 8l-3.5 3.5"/></svg>
      </button>
    </footer>
  </aside>

  <template data-modello>
    <li class="riga">
      <span class="riga__dentro">
        <span class="riga__tassello" aria-hidden="true"></span>
        <span class="riga__testo">
          <span class="riga__nome"></span>
          <span class="riga__variante"></span>
          <span class="quantita">
            <button type="button" class="quantita__tasto" aria-label="One less" data-meno><svg viewBox="0 0 12 12" aria-hidden="true"><path d="M2.5 6h7"/></svg></button>
            <span class="quantita__numero rullo" data-numero></span>
            <button type="button" class="quantita__tasto" aria-label="One more" data-piu><svg viewBox="0 0 12 12" aria-hidden="true"><path d="M6 2.5v7M2.5 6h7"/></svg></button>
          </span>
        </span>
        <span class="riga__destra">
          <span class="riga__prezzo rullo" data-prezzo-riga></span>
          <button type="button" class="togli" data-togli>Remove</button>
        </span>
      </span>
    </li>
  </template>

  <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.

49 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 “Cart drawer” 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 warm white ground, the page of Wren & Loom, a made-up home goods shop: the brand, three links, the bag top right, the title «Slow things for the home» and three products, a linen throw, a stoneware mug and a beeswax candle, each a soft tile of colour with a faint weave, the name, the price and an Add to bag pill with a black plus. Pressed, the pill sinks, the plus turns a quarter and the tile hops; from the right the cart comes out like a drawer, going two pixels too far and settling back, while a dark shade falls over the page and the page steps back a breath to the left. Inside the drawer the header, the shipping box and the footer come in one after another. The new line comes in at the top with a small settle, its tile straightening on a spring, and the lines already there move down to make room. The count on the bag appears and rolls, the bag hops, the subtotal rolls digit by digit from the right. The free shipping bar fills towards the 100 dollar goal and the sentence says how much is left, the figure rolling; at the goal the sentence rolls to Free shipping unlocked with its tick, the ring at the end of the bar takes the colour and draws a tick, the bar swells for a moment, a thread of light runs along it and then over the black Checkout pill. Minus and plus change the quantity (at one, minus shakes and stays), Remove slides the line away and the others close up. The drawer closes with its button, with Esc or with a click outside, and the page comes forward with a small bounce. Left alone, the page runs through by itself.

How it works

The drawer

The cart is an aside fixed to the right, min(400px, 92vw) wide, moved out with xPercent: 104. On opening a timeline takes it to xPercent -0.6 in DRAWER seconds with power4.out and then to 0 with sine.inOut: two pixels too far and back, like a drawer reaching its end. At the same time the shade goes to DIM opacity and the page goes to x: -SHIFT (at most 3% of the width, so on a phone the brand never leaves the side) and scale 0.988, so it seems to take a step back. Closing runs it all the other way, the page with back.out.

The line that comes in at the top

Before adding the line the positions of the lines already there are read with getBoundingClientRect; the new line goes at the head of the list, the positions are read again and each line starts from y equal to the difference and returns to 0 with back.out (the FLIP trick). The new line comes in from above, small and see-through, with back.out(1.6). Removing a line is the reverse: it slides right and fades, then its height goes to 0 and the others close up by themselves.

The digits and the bar

Every number is a row of columns from 0 to 9: each column rises with its own yPercent, the rightmost digit first, and when the number of digits changes the width slides from the old to the new. The bar is a fill in scaleX from 0 to subtotal divided by GOAL; at the goal the sentence rolls to its second line, the two ticks draw themselves with strokeDashoffset (autoRound off) and a white thread runs along the bar.

Values to change

NameFileDefaultWhat it changes
DRAWERscript.js0.6Seconds the drawer takes to slide out from the right.
SHIFTscript.js18Pixels the page steps back while the drawer is open.
DIMscript.js0.3How dark the page behind the drawer gets (0 = none, 1 = black).
SETTLEscript.js0.6Seconds a new line takes to settle at the top.
ROLLscript.js0.5Seconds the digits take to roll.
FILLscript.js0.8Seconds the free shipping bar takes to fill.
GOALscript.js100The subtotal, in dollars, from which shipping is free.
LIGHTscript.js0.9Seconds the thread of light takes to run along the bar.
AUTOscript.js1Seconds before the page runs through by itself, when nobody touches it.

Try them in the Playground

When to use it

For the cart of an online shop that doesn’t want to send the buyer to another page: add, look, change the quantity and go back to the products. The free shipping bar is for when there’s a threshold to reach.

On phones

The same animations. The drawer takes almost the whole width and leaves a strip of the dimmed page to close it with a finger; the menu links hide, product name and price go on two lines and the pill just says Add on the narrowest screens. On short screens the tax note and the lines’ variant hide.

With reduced motion

No sliding and no bounces: the drawer and the shade fade in, the lines fade in, the digits and the bar change at once, the ticks are already drawn.

Pitfalls

  • The line positions for the FLIP must be read before and after the insertion in the same frame: read after a tween, the new line has already pushed them and the difference is zero.
  • With ticks drawn with strokeDashoffset and pathLength 1, GSAP’s autoRound must be off, or they appear at once instead of drawing.
  • The closed drawer must have visibility: hidden and not just sit off screen, or the Tab key walks into its invisible buttons.

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 21 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