Skip to content
animorio
IT
All components

Train coach picker

Tickets, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.2 KBGSAP 28 KBFreeDownload the zip

Picking a coach on a train ticket: six coaches in a row, A to F, each with its windows and a small bar saying how full it is. Pick one and the train slides along the rails and stops with a slight bounce bringing it to the middle; at the top the free seats count to the new number and below it rolls what the coach is for: quiet, bistro, bikes, families. The button picks it and confirms with a tick.

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>
<!--
  "Train coach picker" 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>Train coach picker</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">
    <!-- picking a coach on a train ticket: the coaches stand in a row with how full they are, the train slides
         to bring the chosen one to the middle, and below it its free seats roll in with what the coach is for -->
    <section class="tc" data-tc aria-labelledby="tc-title">
      <header class="tc__head">
        <span class="tc__name"><b id="tc-title">Choose your coach</b><span>IC 512 to Lyon, leaves 14:07</span></span>
        <span class="tc__free" aria-live="polite"><b><span data-outfree>23</span></b><span class="tc__freeword"><span data-freeword>seats free</span></span></span>
      </header>

      <div class="tc__rail" data-rail>
        <div class="tc__train" data-train role="group" aria-label="Coaches">
          <span class="tc__nose" aria-hidden="true"></span>
          <button class="tc__coach" type="button" data-coach data-letter="A" data-kind="First class" data-note="Wide seats, power at every seat" data-free="12" data-seats="48" aria-pressed="false" aria-label="Coach A, First class, 12 seats free"><b>A</b><span class="tc__win" aria-hidden="true"><i></i><i></i><i></i></span><span class="tc__load" aria-hidden="true"><i style="width:75%"></i></span></button>
          <button class="tc__coach" type="button" data-coach data-letter="B" data-kind="Standard" data-note="Nearly full, tables for four" data-free="4" data-seats="64" aria-pressed="false" aria-label="Coach B, Standard, 4 seats free"><b>B</b><span class="tc__win" aria-hidden="true"><i></i><i></i><i></i></span><span class="tc__load" aria-hidden="true"><i style="width:94%"></i></span></button>
          <button class="tc__coach" type="button" data-coach data-letter="C" data-kind="Quiet zone" data-note="No calls, phones on silent" data-free="23" data-seats="64" aria-pressed="true" aria-label="Coach C, Quiet zone, 23 seats free"><b>C</b><span class="tc__win" aria-hidden="true"><i></i><i></i><i></i></span><span class="tc__load" aria-hidden="true"><i style="width:64%"></i></span></button>
          <button class="tc__coach" type="button" data-coach data-letter="D" data-kind="Bistro" data-note="Coffee and sandwiches, no seats" data-free="0" data-seats="0" aria-pressed="false" aria-label="Coach D, Bistro, no seats"><b>D</b><span class="tc__win" aria-hidden="true"><i></i><i></i><i></i></span><span class="tc__load" aria-hidden="true"><i style="width:100%"></i></span></button>
          <button class="tc__coach" type="button" data-coach data-letter="E" data-kind="Bikes" data-note="Six bike hooks, fold-down seats" data-free="31" data-seats="56" aria-pressed="false" aria-label="Coach E, Bikes, 31 seats free"><b>E</b><span class="tc__win" aria-hidden="true"><i></i><i></i><i></i></span><span class="tc__load" aria-hidden="true"><i style="width:45%"></i></span></button>
          <button class="tc__coach" type="button" data-coach data-letter="F" data-kind="Family" data-note="Play corner, space for prams" data-free="40" data-seats="64" aria-pressed="false" aria-label="Coach F, Family, 40 seats free"><b>F</b><span class="tc__win" aria-hidden="true"><i></i><i></i><i></i></span><span class="tc__load" aria-hidden="true"><i style="width:38%"></i></span></button>
        </div>
        <span class="tc__track" aria-hidden="true"></span>
      </div>

      <div class="tc__info">
        <button class="tc__step" type="button" data-prev aria-label="Previous coach"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M9.500 3.500 5 8l4.500 4.500"></path></svg></button>
        <span class="tc__what"><b class="tc__roll"><span data-outkind>Quiet zone</span></b><span class="tc__roll tc__roll--sub"><span data-outnote>No calls, phones on silent</span></span></span>
        <button class="tc__step" type="button" data-next aria-label="Next coach"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6.500 3.500 11 8l-4.500 4.500"></path></svg></button>
      </div>

      <button class="tc__go" type="button" data-go><svg viewBox="0 0 16 16" aria-hidden="true"><path pathLength="1" d="m3.500 8.300 3 3 6-6.600"></path></svg><span class="tc__gotext"><span data-golabel>Pick coach C</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.

26 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 “Train coach picker” 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, a dark card: “Choose your coach”, “IC 512 to Lyon, leaves 14:07” and on the right “23”, “seats free”. Below, a train longer than the card, fading at both edges: the coaches are rounded boxes with their letter, three windows and a small bar of how full they are, coupled to one another, above a track with its sleepers. The one in the middle, C, has an orange edge, lit windows and an orange bar. On opening the train pulls in from the right and stops with a bounce. Below, between two arrows, “Quiet zone” and “No calls, phones on silent”, then the orange button “Pick coach C”. Tap the next arrow and the train slides by one coach and settles: D gives a small hop, the seats count to 0, “seats here”, “Bistro”, and the button goes off into “No seats in coach D”. Next again: E, “31 seats free”, “Bikes”. The button picks it: it empties into an outline with a tick drawing itself and “Coach E picked”. The coaches can also be tapped directly.

How it works

The sliding train

The coaches are buttons in a row wider than the card. The shift is half the rail’s width minus the centre of the chosen coach: GSAP takes the row’s x there on a spring, and a mask fades both edges.

The state

Two numbers: the coach looked at and the one picked. From there the lit edge, the arrows off at both ends, the button’s label and the button disabled when the coach has no seats.

The seats

Each coach carries its data in attributes. The number of free seats is an object taken to the new value in COUNT seconds and written rounded, while the words roll in the train’s direction.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#ff6a3dThe colour of the chosen coach and of the button.
STARTscript.jsCThe coach chosen on opening, from A to F.
GLIDEscript.js1How long the train takes to slide to the chosen coach.

Try them in the Playground

When to use it

On the site of a railway company or a travel agency, at the booking step where you choose where to sit; and on event and hotel sites selling the train together with the ticket or the room. With other boxes it works for a ferry’s decks or a stadium’s sectors.

On phones

The same card, as wide as the screen minus the margins: three whole coaches show with the two at the sides fading, the arrows are 34 pixels wide and the train recentres by itself on resize. The card is about 285 pixels tall and fits the phone box.

With reduced motion

The train does not slide: the chosen coach is in the middle at once, the free seats change without counting and the labels without rolling. The demo’s pointer does not start.

Pitfalls

  • Train, time and seats are made up: on a real site the free seats come from the booking system and change while you look.
  • The chosen coach is not told by colour alone: it sits in the middle, has aria-pressed and each coach’s label says its kind and seats.
  • The attributes holding the coaches’ data and those marking where the script writes have different names: with the same name querySelector takes the first coach and writes into it.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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