Skip to content
animorio
IT
Back to the library

Weight-based dosage

SVG, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.0 KBGSAP 28 KBFreeDownload the zip

A medicine’s dose in a vet clinic app: move the weight slider and the graduated syringe fills up to the dose, with the plunger arriving on a spring and settling, the marker showing the point on the scale and the millilitres counting in large type. The weight reads in kilos or pounds.

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>
<!--
  "Weight-based dosage" 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>Weight-based dosage</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">
    <!-- the dose of a vet clinic app: move the weight and the oral syringe fills up to the dose -->
    <section class="ds" data-ds aria-label="Dose by weight">
      <header class="ds__head">
        <span class="ds__who"><strong>Miso</strong><span>Arloxin oral, <span data-outstrength>20</span> mg/mL</span></span>
        <div class="ds__units" role="radiogroup" aria-label="Weight unit">
          <i class="ds__thumb" data-thumb aria-hidden="true"></i>
          <button type="button" role="radio" aria-checked="true" data-unit="kg">kg</button>
          <button type="button" role="radio" aria-checked="false" data-unit="lb">lb</button>
        </div>
      </header>

      <p class="ds__dose"><span class="ds__num"><b data-outdose>0.45</b><i>mL</i></span><span class="ds__mg"><b data-outmg>9</b> mg per dose<br>every 12 hours</span></p>

      <svg class="ds__syringe" viewBox="0 -2 340 84" role="img" aria-label="Oral syringe filled to the dose" data-svg>
        <g data-plunger>
          <rect class="ds__rod" x="6" y="30" width="156" height="8" rx="2"></rect>
          <rect class="ds__handle" x="158" y="8" width="8" height="52" rx="3.500"></rect>
          <rect class="ds__stopper" x="0" y="13.500" width="10" height="41" rx="2.500"></rect>
          <path class="ds__ribs" d="M3.500 16v36M6.500 16v36"></path>
        </g>
        <rect class="ds__liquid" x="30" y="13.500" width="0" height="41" data-liquid></rect>
        <rect class="ds__gloss" x="30" y="17" width="0" height="5" rx="2.500" data-gloss></rect>
        <path class="ds__barrel" d="M30 12h150M30 56h150M180 6v56M30 12v15h-11a3 3 0 0 0-3 3v8a3 3 0 0 0 3 3h11V56"></path>
        <g class="ds__ticks" data-ticks></g>
        <path class="ds__mark" d="M0 9l-4.500-7h9Z" data-mark></path>
      </svg>

      <div class="ds__weight">
        <label class="ds__label" for="ds-weight">Weight</label>
        <span class="ds__value"><b data-outweight>4.5</b> <span data-outunit>kg</span></span>
        <input class="ds__range" id="ds-weight" type="range" min="1" max="40" step="0.5" value="4.5" data-range>
      </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.

25 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 “Weight-based dosage” 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 light card: at the top “Miso” and the medicine (“Arloxin oral, 20 mg/mL”), on the right the choice between kg and lb with its sliding tile. Below, the dose in large type, “0.45 mL”, with the milligrams per dose and how often next to it. In the middle an oral syringe drawn in line, with a scale from 0 to 5 millilitres: the coral liquid fills the barrel up to the dose, the dark plunger with its rod follows, a light reflection runs along the top of the liquid and a coral marker above the barrel shows the exact point. At the bottom, the weight slider. As you move it the dose is worked out again: the plunger goes to the new point on a spring, overshoots slightly and settles, the liquid and the marker go with it and the big figure counts along. Switching to lb rewrites the weight in pounds with a small hop and the dose does not change.

How it works

From weight to dose

The dose is the weight times the milligrams per kilo, divided by the bottle’s strength. The weight always stays in kilos inside the script: pounds are only a way of writing it.

One number moves the syringe

GSAP takes a single number, the millilitres on show, to the new dose on a spring. On every frame one function turns it into the liquid’s width, the position of plunger and marker and the big figure.

The script writes the scale

The scale’s ticks and numbers come from the syringe’s capacity: change the millilitres it holds and the scale redraws itself.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#ef6a4cThe colour of the liquid, the unit and the dose marker.
MG_PER_KGscript.js2How many milligrams per kilo of weight (a number invented for the demo).
STRENGTHscript.js20The bottle’s strength, in milligrams per millilitre.
SYRINGEscript.js5How many millilitres the syringe holds.
SPRINGscript.js1How much the plunger bounces when the dose changes.

Try them in the Playground

When to use it

In the app or site of a vet clinic, a pharmacy or a telehealth service, next to the prescription; in any calculator where one quantity depends on another and you want to show how much it is: fertiliser per litre of water, detergent per load, coffee per cup.

On phones

The card is at most 332 pixels wide and narrows with the screen; the big figure and the gaps are sized on height too, so it fits a short window. The slider is a real range input, with a 24 pixel knob, and lets the page scroll vertically.

With reduced motion

Plunger, liquid and figure go straight to the new dose, with no spring and no counting; the unit tile moves at once. The demo’s pointer does not start.

Pitfalls

  • Medicine, strength and milligrams per kilo are invented: this is the demo of an interface, not medical guidance. In a real product the dose is set by the prescriber and comes from the server.
  • The plunger moves by writing its group’s transform attribute from an animated number: this way it does not depend on the svg’s box and follows the liquid to the pixel.
  • If the dose exceeds the capacity, the syringe stops full: a real product should say there to use a larger one.
  • The dose is not told by the drawing alone: the figure is there, and every change is read out in an aria-live region and in the slider’s text.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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