Skip to content

Recipes

Scripted effects with toon.js that combine several principles: a character jump, a throw along a path, and reduced motion on canvas.

Edit this page

Each recipe uses toon.js and combines several principles in one script. For one class on an ordinary element, see HTML.

Each recipe runs on the screen, and Show code opens its code. The snippets are read from the example pages in examples/recipes/, so what you see is what runs. Only the page styling (the panel, fonts and theme colors) is left out.

This uses anticipation, squash and stretch, slow in and slow out and timing. Each tween is one beat, and sequence plays them in order. A withSquash pivot at the ball’s base keeps it planted while it squashes:

Arcs, with squash and stretch along the direction of travel. A quadratic arc run with linear timing follows the same path as a real throw:

toon.css handles reduced motion for you, and data-motion="play" on an ancestor lets a reader opt back in. On canvas, check the media query yourself and either jump to the end state or slow decorative motion right down:

When the clock is frozen, tweens stop advancing. Anything that must still end up in its final state, such as the values your onComplete would set, should be set directly instead of animated.