Skip to content
animorio
IT
All components

Sort by menu

Menus, HoverGSAP, CSS onlyMediumCompressed weight: Demo 8.2 KBGSAP + Flip 37 KBFreeDownload the zip

The «Sort by» menu of a ceramics shop’s catalogue, on white, in the style of real product interface pieces: the pill opens into a menu on a spring, a grey highlight slides under the option, the green check draws itself on the chosen order and the six product cards travel to their new places with Flip, lifting a little on the way, while the price or rating they are sorted by lights up one after another.

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>
<!--
  "Sort by menu" 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 Sort by menu that reorders the catalogue</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 catalogue of a ceramics shop: the Sort by pill opens a menu on a spring, the highlight follows the pointer,
         the check moves to the chosen order and the six products below travel to their new places with Flip,
         lifting a little on the way, while the value they are sorted by lights up -->
    <section class="card" data-card aria-label="Shop catalogue">
      <header class="head">
        <span class="mark" aria-hidden="true">
          <svg viewBox="0 0 24 24"><path d="M8 4h8M9 4c0 3-3.5 4.5-3.5 9a6.5 6.5 0 0 0 13 0C18.5 8.5 15 7 15 4M7 14h10"/></svg>
        </span>
        <span class="head__text">
          <span class="head__name" data-name>Kilnhouse</span>
          <span class="head__sub" data-sub>6 pieces</span>
        </span>

        <div class="sort" data-sort>
          <button class="pill" type="button" data-pill aria-haspopup="listbox" aria-expanded="false" aria-controls="sort-menu">
            <span class="pill__key">Sort</span>
            <span class="pill__win" data-win><span class="pill__val" data-val>Newest</span></span>
            <svg class="pill__chev" data-chev viewBox="0 0 24 24" aria-hidden="true"><path d="m7 10 5 5 5-5"/></svg>
          </button>

          <div class="menu" id="sort-menu" data-menu role="listbox" aria-label="Sort by" tabindex="-1">
            <span class="menu__title">Sort by</span>
            <span class="menu__hl" data-hl aria-hidden="true"></span>
            <div class="menu__list" data-list></div>
          </div>
        </div>
      </header>

      <ul class="grid" data-grid aria-live="polite"></ul>
    </section>

    <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="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/Flip.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.

20 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 “Sort by menu” 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 white sits the card of Kilnhouse, an invented ceramics shop: the vase mark, the name, «6 pieces» with the chosen order in words, and on the right the «Sort · Newest» pill with its little chevron. Below, six cards in three columns, each with a real photograph of its piece on a museum grey ground (the stoneware mug with the ridged rim, the pale green bowl, the milk white vase, the white plate, the small clay pitcher, the faceted glass tumbler), the name, the price and the rating with a small star; the two newest carry a New label. Pressed, the pill squashes and the menu opens: a white sheet dropping on a spring from its corner, the four options arriving in a row, each with its small drawn icon, and a grey highlight sliding under the option the pointer is on. Picking an order, the green check is wiped off the old option and drawn on the new one, the pill’s label leaves upwards while the new one comes in from below widening a little, the pill grows or shrinks with it, the chevron turns back down and the line under the name says the new order. Meanwhile the cards travel to their new places one after another, the ones that move lift a little with their shadow and settle back with a small elastic, and when sorting by price or rating that value lights up green on every card, in the new order. A drawn pointer sorts by price low to high, by rating, by price high to low and back to newest; it also really works, with mouse, finger and the arrow keys, Enter and Esc.

How it works

The menu opening from its corner

The menu sits in absolute position under the pill, with transform-origin near its top-right corner: it opens with a fromTo of scale from 0.92, y from minus eight pixels and opacity, with back.out, and the options arrive with a three-hundredths stagger. Closed, it is hidden with visibility, so it takes neither taps nor tabs.

The highlight that follows the option

A single grey pill behind the options: on every pointerenter or focus it goes to the option’s offsetTop plus the list’s with back.out, and when the pointer leaves the menu it goes back to the chosen option. One element for all options, instead of a hover per option, shows the movement.

The check and the pill

The checks are paths with a strokeDasharray as long as themselves: the old one is wiped by taking strokeDashoffset to the length, the new one is drawn from there to zero. The pill’s label is a clone coming in from below with yPercent while the old one leaves upwards, and the window takes the width of the new label, measured first with an invisible element.

Reordering with Flip

Flip.getState reads where the six cards are, the new order puts them back in the grid with appendChild and Flip.from takes them from the old position to the new one with power3.inOut and a stagger. The lift lives on each card’s inner child, scale and box-shadow in a small timeline, so Flip’s transform and the lift’s do not cancel each other.

Values to change

NameFileDefaultWhat it changes
SHOPscript.jsKilnhouseThe shop’s name at the top of the card.
ACCENTscript.js#2f6b52The colour of the check, of the New labels and of the value the cards are sorted by.
FLIP_TIMEscript.js0.75The seconds each product takes to reach its new place.
STAGGERscript.js0.035The seconds between one product starting and the next.
LIFTscript.js1.04How much a product lifts while it travels (1 means none).
MENU_SPRINGscript.js1.6The menu’s bounce when it opens (0 means none).
PAUSEscript.js1.1The seconds the autopilot waits on each order.

Try them in the Playground

When to use it

For an online shop’s catalogue, a list of products, rooms, events or articles, and anywhere people can choose the order things are shown in.

On phones

The card takes the full width minus the margins and the three columns narrow; below 380 pixels the word «Sort» leaves the pill and the menu gets a little narrower, so it stays inside the card. Options are 36 pixels tall for a finger.

With reduced motion

No springs and no travel: the menu fades in and out, the check changes at once, the pill’s label changes in place and the grid fades out and back in already in the new order. The drawn pointer stays hidden.

Pitfalls

  • The cards’ lift written on the same element Flip moves was wiped out halfway: it lives on the inner child, and Flip moves only the parent.
  • The pill’s new, longer label wrapped inside the window while it widened: the right width is measured first, with an invisible element, and the label never wraps.
  • The real photographs come in different shapes and sizes: each thumbnail crops them with object-fit: cover and its own object-position, so the piece sits in the middle of the card and none looks smaller than the others.

Libraries

GSAP 3.15.0, Flip (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 + Flip 37 KB.

Testing

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