Skip to content
animorio
IT
Back to the library

Tug-of-war poll

Physics, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.8 KBGSAP 28 KBFreeDownload the zip

A live poll between two answers, on warm white, as a tug of war: a taut rope with a knot, the centre line and the two shares at the ends. Every vote coming in pulls the knot its way on a real spring, which swings and settles; the side ahead takes the colour. Voting gives the rope a yank, and when the knot crosses the centre line the colour changes side.

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>
<!--
  "Tug-of-war poll" 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>Tug-of-war poll</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">
    <!-- a live poll as a tug of war: the knot on the rope pulled by the votes on a real spring,
         the centre line to cross and the two shares at the ends -->
    <section class="tw" data-tw aria-label="Live poll">
      <header class="tw__head"><span class="tw__tag">Live poll</span><span class="tw__votes"><b data-outvotes>240</b> votes</span></header>
      <h1 class="tw__ask">What should we build next?</h1>
      <div class="tw__ends">
        <span class="tw__end" data-end="0"><b><span data-outpct="0">47</span>%</b><i>Dark mode</i></span>
        <span class="tw__end" data-end="1"><b><span data-outpct="1">53</span>%</b><i>Offline sync</i></span>
      </div>
      <svg class="tw__rope" data-rope aria-hidden="true">
        <line class="mid" data-mid></line>
        <path class="half" data-half="0"></path>
        <path class="half" data-half="1"></path>
        <rect class="post" data-post="0" width="4" height="18" rx="2"></rect>
        <rect class="post" data-post="1" width="4" height="18" rx="2"></rect>
        <circle class="knot" data-knot r="7"></circle>
      </svg>
      <div class="tw__btns">
        <button type="button" class="tw__btn" data-side="0" aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path pathLength="1" d="m3.600 8.400 2.900 2.900 5.900-6.600"></path></svg><span>Dark mode</span></button>
        <button type="button" class="tw__btn" data-side="1" aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path pathLength="1" d="m3.600 8.400 2.900 2.900 5.900-6.600"></path></svg><span>Offline sync</span></button>
      </div>
    </section>
    <span class="live" aria-live="polite" data-live></span>

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

22 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 “Tug-of-war poll” 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 warm white, a rounded card: “Live poll” in coral and on the right “240 votes”. Below, the question: “What should we build next?”. Then the two shares in large type, “47%” with “Dark mode” on the left and “53%” with “Offline sync” on the right: the one ahead is coral. Under them, a rope stretched between two posts with a round knot, and a dashed line at the centre: the knot sits a little to the right, on the side that leads, and that half of the rope is coral. Votes keep coming in: with each one the count climbs, the shares change and the knot gets a small yank and swings back to its place. At the bottom two buttons, “Dark mode” and “Offline sync”. Tapping “Dark mode” turns the button dark with a tick, the rope yanks hard to the left and for a few seconds the votes come mostly from that side: the knot crosses the centre line, swells for a moment, and the coral moves to the left share and the left half.

How it works

The knot is a spring

The knot has a position and a velocity. On every frame a force pulls it towards where it belongs and friction slows it: the swing and the settling come out by themselves, with no drawn curves.

Where it wants to be

Where it belongs depends on the share of the votes: half and half is the centre, and every point of lead moves it towards the side ahead.

A vote is a yank

Every vote changes the count and also gives the knot a push of velocity its way; your own vote gives a strong one. The rope has its own small spring too, which makes it quiver.

Who is ahead

When the count shown changes sign, the colour class moves to the other share and the other half of the rope, and the knot swells once.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#e2502fThe colour of the side ahead: its share and its half of the rope.
STIFFscript.js140How stiff the spring taking the knot to its place is.
DAMPscript.js11How much it is damped: low, the knot swings for long; high, it stops at once.
RATEscript.js1.4How many times a second the others’ votes come in.
LOOPscript.jstrueLeft alone, the demo’s pointer votes, its side rallies and then it starts again.

Try them in the Playground

When to use it

In the poll of a live stream, an event or a meeting, on the page where a community picks between two features, or in a challenge between two teams; the same rope and knot carries a comparison between two products, the balance between income and spending or a fundraiser’s progress against its goal.

On phones

The card is at most 348 pixels wide and about 250 tall, and narrows with the screen: the rope is redrawn on the width it finds. The two buttons are 44 pixels tall and half the card wide.

With reduced motion

No spring, yanks or swinging: with every vote the knot is already in its place and the numbers change in one step; the chosen button has its tick already drawn. The demo’s pointer does not start.

Pitfalls

  • The spring is stepped by hand on every frame: the time step has to be capped (here at a twentieth of a second, split in four), or on coming back to a tab left in the background the knot shoots away.
  • The knot exaggerates the lead to be readable: at sixty to forty it is already almost at the end. The real numbers are the two shares, always written.
  • The others’ votes are simulated here with a fixed sequence; in a real product they come from the server and the function pulling the rope is the same.
  • Who is ahead can be read from the numbers, not only the colour; the vote given is told by aria-pressed and an aria-live region.
  • The answers and the votes are invented.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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