Skip to content

Secondary action

Small supporting motions (glances, swings, blinks) that add life.

Edit this page

The primary action is what a character is doing, such as walking. Secondary actions support it: arms swinging against the step, eyes glancing around, an occasional blink. They make the main action richer, but they never compete with it.

Now showing: Secondary actionOpen the Secondary action 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>08 · Secondary action — 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: 300px; margin: var(--space-sm) 0; }
</style>
</head>
<body>
<h1>Secondary action</h1>
<p>The primary action is Loop's walk: the bob and the feet. Secondary actions — swinging arms, idle glances,
the odd blink — add personality without stealing focus.</p>
<label><input id="sec" type="checkbox" checked> Secondary action</label>
<canvas id="c" role="img" aria-label="Loop walks in place. Its arms swing, its eyes glance around and it blinks now and then. One switch turns all of these secondary actions off, leaving only the walk."></canvas>
<p class="demo-try">Toggle the secondary actions to see how flat the walk gets without them.</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('08-secondary-action', (document, Toon, DemoTheme) => {
const T = DemoTheme; // design tokens, live (see demo-theme.js)
const { createStage, ticker, noise, blink } = Toon;
const stage = createStage(document.getElementById('c'));
const { ctx } = stage;
const sec = document.getElementById('sec');
let x = null; // starts mid-stage, so a paused first frame shows the walk
stage.loop((dt, t) => {
const ground = stage.height - 40, H = 110, speed = 110;
if (x === null) x = stage.width * 0.45;
x += speed * dt; if (x > stage.width + 80) x = -80;
const phase = t * Math.PI * 2 * 1.6;
const bob = Math.abs(Math.cos(phase)) * 8; // primary: walk bounce, highest as the feet pass
const cy = ground - H / 2 - 12 - bob;
stage.clear();
ctx.fillStyle = T.ground; ctx.fillRect(0, ground, stage.width, 40);
ctx.fillStyle = T.groundLine; ctx.fillRect(0, ground, stage.width, 2);
for (const side of [0, 1]) { // feet, alternating
// A foot swings forward (f rising, cos > 0) in the air, then plants and slides back under the moving body.
// Stride 17px: at 1.6 steps/s a planted foot then moves back as fast as the body moves on (no net skating).
const f = Math.sin(phase + side * Math.PI), lift = Math.max(0, Math.cos(phase + side * Math.PI)) * 8;
ctx.fillStyle = T.ink; ctx.beginPath();
ctx.ellipse(x + f * 17, ground - 5 - lift, 11, 5, 0, 0, 7); ctx.fill();
}
const on = sec.checked, swing = Math.sin(phase) * 28;
Cast.draw(ctx, 'loop', { x, y: cy, h: H, fill: T.secondary, ink: T.ink, bg: T.surface, feet: false, noWink: true,
arms: on ? { r: { a: 15 + swing, b: 25 }, l: { a: 15 - swing, b: 25 } } // [SECONDARY] arms swing against the legs
: { r: { a: 8, b: 4 }, l: { a: 8, b: 4 } },
look: on ? { x: 0.4 + noise(t * 0.6) * 0.8, y: noise(t * 0.4 + 9) * 0.6 } : { x: 0.6, y: 0 }, // idle glances
blink: on ? blink(t, { every: 2.8 }) : 0 });
});
});
</script>
</body>
</html>

Add .toon-sway, .toon-bob or .toon-blink to small parts of something that already has a main action. This snippet runs as-is:

<link rel="stylesheet" href="toon.css">
<!-- Primary: the card settles in. Secondary: sway, blink, bob -->
<div id="card" class="toon-settle" style="display:flex;
align-items:center; gap:16px; max-width:300px;
padding:16px; border:2px solid; border-radius:16px">
<span class="toon-sway" style="display:grid;
justify-items:center; flex:none">
<span style="display:grid; place-items:center;
width:34px; height:34px; border-radius:50%;
border:2.5px solid; background:var(--toon-color)">
<span class="toon-blink" style="display:flex;
gap:6px"><b style="width:4px; height:7px;
border-radius:2px; background:currentColor"></b><b
style="width:4px; height:7px; border-radius:2px;
background:currentColor"></b></span>
</span>
<span style="width:3px; height:26px;
background:currentColor"></span>
</span>
<p style="margin:0">Your garden is growing
<span class="toon-bob" style="display:inline-block;
padding:0 8px; border:2px solid; border-radius:99px;
font-weight:600">3 new</span></p>
</div>
<button id="replay" type="button">Replay</button>
<script>
// Replay a one-shot preset: remove it, force a reflow, add it.
document.getElementById('replay').onclick = () => {
const card = document.getElementById('card');
card.classList.remove('toon-settle');
void card.offsetWidth;
card.classList.add('toon-settle');
};
</script>

Below, the card’s entrance is the primary action. Press Replay to watch it again while the flower and badge keep moving:

Now showing: CSS secondary actionOpen the CSS secondary action demo on its own page (opens in a new tab)

.toon-sway tilts 4 degrees each way from the bottom edge, .toon-bob floats up 5px and back, and .toon-blink squashes to a line about once every 4 seconds. Each runs on a multiple of --toon-duration, so they drift in and out of step instead of pulsing together.

This character runs as-is. The arms swing from the walk’s own phase, so they stay in step. noise() moves the eyes in smooth, random glances, and blink() closes them at a slightly irregular rhythm.

  • Keep amplitudes small. If people notice the secondary action first, it’s too big. The arms here swing about 80 degrees; the eyes move 6px at most.
  • Drive it from the primary motion. Arms that read the walk’s phase stay in step for free, while an independent loop can feel disconnected.
  • Give idle motion its own clock. Glances and blinks that follow the walk look mechanical. A slow noise() and an irregular blink feel like a mind at work.
  • Turn it off and compare. Untick Secondary action in the demos: the walk still works, but the character looks lifeless.

For every option, see the Canvas secondary action functions and the CSS secondary action presets.