Skip to content

Anticipation

A small wind-up before the main move: button presses, jumps, launches.

Edit this page

Before jumping, you crouch. Before throwing, you pull your arm back. Anticipation is a small move in the opposite direction of the main action. It prepares the viewer’s eye, so the action reads clearly even when it’s fast.

Now showing: AnticipationOpen the Anticipation demo on its own page (opens in a new tab)
Show the demo's source

The complete page: it loads toon.css and toon.js, plus demo-theme.js (theme colors), demo-runtime.js (gives the demo its own clock) and, for the characters, cast.js.

<!doctype html>
<html lang="en" data-style="saturday">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>02 · Anticipation — toon</title>
<link rel="stylesheet" href="../src/toon.css">
<link rel="stylesheet" href="demo.css">
<style>
body { font-size: 15px; line-height: 1.5; max-width: var(--demo-max-width); margin: 2rem auto; padding: 0 1rem; }
canvas { display: block; width: 100%; height: 320px; margin: var(--space-sm) 0; cursor: pointer; }
</style>
</head>
<body>
<h1>Anticipation</h1>
<p>Before a big action, a small opposite move (the crouch) tells the viewer what is about to happen.
</p>
<label><input id="antic" type="checkbox" checked> Anticipation (crouch before the jump)</label>
<canvas id="c" style="cursor:pointer" role="img" aria-label="Dot crouches down, then jumps and lands. With anticipation switched off, Dot jumps without crouching first."></canvas>
<p class="demo-try"><button type="button" class="demo-act" id="act">Jump</button> Press <i>Jump</i> or click the canvas, then turn anticipation off and compare.</p>
<script src="../src/toon.js"></script>
<script src="demo-theme.js"></script>
<script src="cast-shapes.js"></script>
<script src="cast.js"></script>
<script src="demo-runtime.js"></script>
<script>
ToonDemos.register('02-anticipation', (document, Toon, DemoTheme) => {
const T = DemoTheme; // design tokens, live (see demo-theme.js)
const { createStage, ticker, tween, sequence, ease, withSquash, groundShadow } = Toon;
const stage = createStage(document.getElementById('c'));
const { ctx } = stage;
// Reduced motion opens on the crouch, the pose that shows the principle (nothing moves until Play and Jump).
const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
const hero = { y: 0, sy: still ? 0.62 : 1 }; // y = height above ground; sx = 1/sy keeps volume
const set = v => Object.assign(hero, v);
let mood = still ? 'focused' : 'neutral';
const to = (pose, duration, e, m) => () => { if (m) mood = m; return tween({ from: { ...hero }, to: pose, duration, ease: e, onUpdate: set }); };
let busy = false;
async function jump() {
if (busy) return; busy = true;
await sequence(
document.getElementById('antic').checked
? to({ y: 0, sy: 0.62 }, 280, ease.outQuad, 'focused') // [ANTICIPATION] crouch: wind up opposite to the jump
: null,
to({ y: 30, sy: 1.3 }, 90, ease.linear, 'happy'), // take-off: stretch
to({ y: 170, sy: 1 }, 320, ease.outQuad), // rise, slowing into the apex
to({ y: 0, sy: 1.15 }, 300, ease.inQuad), // fall, speeding up
to({ y: 0, sy: 0.7 }, 70, ease.outQuad, 'surprised'), // land: squash
to({ y: 0, sy: 1 }, 420, ease.outElastic), // recover
);
mood = 'neutral'; busy = false;
}
stage.canvas.addEventListener('click', jump);
const character = (c, R) => Cast.draw(c, 'dot', { x: 0, y: 0, h: R * 2, fill: T.primary, ink: T.ink, mood });
stage.loop(() => {
const R = 40, x = stage.width / 2, ground = stage.height - 40;
stage.clear();
ctx.fillStyle = T.ground; ctx.fillRect(0, ground, stage.width, 40);
ctx.fillStyle = T.groundLine; ctx.fillRect(0, ground, stage.width, 2);
groundShadow(ctx, x, ground, R, hero.y, { maxHeight: 250 });
withSquash(ctx, x, ground - R - hero.y, { sx: 1 / hero.sy, sy: hero.sy }, c => character(c, R), { x: 0, y: R });
});
document.getElementById('act').addEventListener('click', jump);
});
</script>
</body>
</html>

To make a control wind up before it acts, add one of the three anticipation presets. This snippet runs as-is:

<link rel="stylesheet" href="toon.css">
<button class="toon-press" style="padding:.6em 1.2em">
Press and hold</button>
<button class="toon-anticipate" style="padding:.6em 1.2em">
Hover, focus or tap</button>
<!-- The ball travels 160px: give it room. -->
<div style="width:100%; max-width:220px; height:40px">
<div id="ball" style="--toon-distance:160px; width:40px;
height:40px; border-radius:50%;
background:var(--toon-color)"></div>
</div>
<button id="launch" style="padding:.6em 1.2em">Launch</button>
<script>
// Replay the one-shot launch: remove the class, then add it back.
const ball = document.getElementById('ball');
document.getElementById('launch').onclick = () => {
ball.classList.remove('toon-launch');
void ball.offsetWidth; // let the browser see the change
ball.classList.add('toon-launch');
};
</script>

Below, hold the first button, hover, tap or tab to the second, and press Launch to replay the ball:

Now showing: CSS anticipationOpen the CSS anticipation demo on its own page (opens in a new tab)

.toon-press dips while held and springs past its size on release. .toon-anticipate crouches before it rises, and .toon-launch pulls back before it shoots forward. For a transition of your own, the --toon-ease-anticipate easing dips backwards first.

Write the action as beats with sequence, and make the first beat the wind-up. Each beat is a tween of the ball’s height and vertical scale. For a single tween, ease.anticipate(s) puts the dip inside the easing curve itself. s sets how far it dips: 1.7 by default, 0 for none.

  • Size the wind-up to the action. A small action needs only a small wind-up. For a big leap, the crouch is the longest beat before it: 280 ms against a 90 ms take-off in the Canvas snippet.
  • Give fast actions more anticipation. If the main move lasts only a few frames, the wind-up is what makes it readable.
  • Move against the action. A wind-up reads only when it goes the other way: down before up, back before forward.
  • Keep it subtle in interfaces. The presets are sized to read in a demo: .toon-press dips about 9%. On a business screen, add .toon-subtle to halve every wind-up, to about 4%.

The Dot demo also shows squash and stretch (Dot stretches on take-off and squashes on landing) and slow in and slow out (the rise slows into the top of the jump).

For every option, see the Canvas timing and sequencing functions and the CSS anticipation presets.