
The slide-to-confirm button
Buttons, Physics, Transitions
A premium component for a drawing and whiteboard app: a dark frame holding a sheet of warm squared paper. Draw a wobbly loop, a box, a triangle or a line with a finger, keep the finger still for half a second and the pill at the top fills: the pencil stroke springs into the perfect shape, turns from graphite to blue, takes a pale fill, a halo that opens once, the four selection handles and its size in the pill. The line becomes a connector arrow.
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>
<!--
"Shape-snapping canvas" 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 drawing canvas that turns sketches into perfect shapes</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 canvas of a sketching app: draw a loop, a box or a line with a finger, keep the finger still for half a
second and the wobbly stroke springs into a perfect circle, rectangle, triangle or straight line, takes the
accent colour, gets its selection handles and its size in the pill at the top -->
<div class="sk" data-wrap>
<span class="sk__halo" aria-hidden="true"></span>
<section class="sk__card" aria-label="Linea sketch canvas">
<header class="sk__bar">
<span class="sk__brand">
<svg class="sk__logo" viewBox="0 0 24 24" aria-hidden="true">
<rect x="1.5" y="1.5" width="21" height="21" rx="7" class="sk__logo-bg"/>
<path d="M7 15.6c2.2-.2 3.3-1.6 4.2-3.6.9-2 2-3.6 5.8-3.8" class="sk__logo-line"/>
</svg>
<span class="sk__file">Onboarding flow<span class="sk__muted"> / Board 2</span></span>
</span>
<span class="sk__actions">
<span class="sk__zoom" aria-hidden="true">100%</span>
<button class="sk__icon-btn" type="button" data-undo aria-label="Undo last stroke">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 7.5 5 11.5l4 4"/><path d="M5.5 11.5h8.2a4.8 4.8 0 0 1 0 9.6H11"/></svg>
</button>
</span>
</header>
<div class="sk__paper" data-paper>
<canvas class="sk__canvas" data-canvas aria-hidden="true"></canvas>
<div class="sk__pill" data-pill aria-hidden="true">
<span class="sk__pill-in">
<svg class="sk__pill-icon" viewBox="0 0 20 20">
<g data-icon="hold"><path d="M4 13.5c1.8-.4 2.6-3.6 4.6-3.8 2-.2 2.4 3 4.4 2.6 1.4-.3 2-2 3-3.3"/></g>
<g data-icon="circle"><circle cx="10" cy="10" r="6"/></g>
<g data-icon="ellipse"><ellipse cx="10" cy="10" rx="7" ry="4.6"/></g>
<g data-icon="rect"><rect x="3.5" y="5" width="13" height="10" rx="1"/></g>
<g data-icon="tri"><path d="M10 3.8 16.6 15.6H3.4Z"/></g>
<g data-icon="line"><path d="M4 15.5 16 4.5"/><path d="M10.5 4.5H16v5.5"/></g>
<g data-icon="none"><path d="M4 12c2-4 4-4 6 0s4 4 6 0"/></g>
</svg>
<span class="sk__pill-text" data-pill-text>Hold to snap</span>
<span class="sk__pill-bar"><span class="sk__pill-fill" data-pill-fill></span></span>
</span>
</div>
<div class="sk__pencil" data-pencil aria-hidden="true">
<div class="sk__pencil-art" data-pencil-art>
<svg viewBox="0 0 44 44">
<path class="sk__p-cap" d="M30.2 4.6 33 1.8a2.4 2.4 0 0 1 3.4 0l5.8 5.8a2.4 2.4 0 0 1 0 3.4l-2.8 2.8Z"/>
<path class="sk__p-band" d="M28.4 6.4 30.2 4.6 39.4 13.8 37.6 15.6Z"/>
<path class="sk__p-body" d="M28.4 6.4 37.6 15.6 14.8 38.4 5.6 29.2Z"/>
<path class="sk__p-shine" d="M29.6 9.6 10.6 28.6"/>
<path class="sk__p-wood" d="M5.6 29.2 14.8 38.4 3.2 42.8a1.6 1.6 0 0 1-2-2Z"/>
<path class="sk__p-lead" d="M2.8 37.6 6.4 41.2 1.6 43a.6.6 0 0 1-.6-.6Z"/>
</svg>
</div>
</div>
</div>
<footer class="sk__dock">
<div class="sk__tools" role="radiogroup" aria-label="Tool">
<span class="sk__tool-bg" data-tool-bg aria-hidden="true"></span>
<button class="sk__tool is-on" type="button" role="radio" aria-checked="true" data-tool="pencil" aria-label="Pencil">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M15.8 4.6l3.6 3.6L8.6 19 4 20l1-4.6Z"/><path d="M13.6 6.8l3.6 3.6"/></svg>
</button>
<button class="sk__tool" type="button" role="radio" aria-checked="false" data-tool="marker" aria-label="Marker">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.5 4.5l5 5-7.6 7.6-5-5Z"/><path d="M6.9 12.1 4.6 17l2.4 2.4 4.9-2.3"/></svg>
</button>
<button class="sk__tool" type="button" role="radio" aria-checked="false" data-tool="fine" aria-label="Fine liner">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18 3.8 20.2 6 9 17.2l-3.6 1.4 1.4-3.6Z"/></svg>
</button>
</div>
<button class="sk__snap" type="button" data-snap aria-pressed="true">
<span class="sk__snap-label">Snap</span>
<span class="sk__switch" aria-hidden="true"><span class="sk__knob" data-knob></span></span>
</button>
</footer>
</section>
</div>
<p class="sr" aria-live="polite" data-live></p>
</main>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
<script src="script.js"></script>
</body>
</html>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.
23 values to change
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 “Shape-snapping canvas” from Animorio and fit it into my siteEvery move longer than 3.5 px records where and when the finger stopped; the GSAP ticker measures how long it has been still and, after 0.14 s, fills the pill's line. At HOLD the stroke is recognised.
If start and end are close and the stroke is at least nearly twice its box's diagonal, it is a loop: the part going back over the start is trimmed. Otherwise it is a line if the chord is at least 84% of the length, and the angle catches on the nearest 45°.
The loop is split at the point farthest from the start and each half is simplified with Ramer-Douglas-Peucker; corners turning less than 24° are dropped. Three corners put forward a triangle, four a rectangle turned along its longest side (level when it nearly is); the circle or ellipse of the box is always in the running. Each candidate is drawn and scored by how far the stroke sits from it on average: the closest wins, and if even that one is past TOLERANCE the stroke stays a sketch.
The stroke and the perfect shape are both resampled into 120 evenly spaced points, the shape starts from the point closest to the stroke's start and runs the same way (the sign of the area). One value k from 0 to 1, on an elastic.out, takes every point from the stroke to the shape: that is why the drawing straightens without sliding.
Every stroke is an object with k, colour, fill, halo, selection and opacity moved by GSAP; the canvas is redrawn only when one of them changes. The handles swell one after another with a small bounce, the arrow opens its head with the fill.
| Name | File | Default | What it changes |
|---|---|---|---|
HOLD | script.js | 0.55 | How many seconds to keep the finger still before the stroke becomes a shape. |
TOLERANCE | script.js | 0.12 | How much wobble a stroke may have and still become a shape: higher forgives more. |
SNAP_TIME | script.js | 0.8 | How many seconds the stroke takes to spring into its shape. |
BOUNCE | script.js | 1 | How springy it is: 0 settles flat, 2 wobbles. |
INK | script.js | 2.6 | The pencil's width, in pixels. |
SPEED | script.js | 1 | 2 = the demo draws twice as fast, 0.5 = half. |
AUTO | script.js | true | Draws by itself until someone touches the sheet. |
For a digital whiteboard, a wireframe and diagram app, a handwritten notes tool for tablets, or the page that shows off a product's ‘draw it and it becomes a shape’ feature.
The same animation with adapted sizes: the window is as wide as the screen and at most 88% of its height tall, the demo's shapes lay out on the sheet's width and a finger draws just like the pencil.
No moving pencil and no spring: the shapes appear already perfect, fading in one after another, with the pill changing its words; drawing by hand, the stroke fades into the shape.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 14 KB; the libraries: GSAP 28 KB.
Tested on 2 November 2026
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.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.