Patterns / Hover and focus linking
Link the words to the steps
Terms in your text point at parts of the diagram. Hovering, focusing or tapping a term jumps the diagram to that step; the active step marks the term back. It works by keyboard and on touch, because every term is a button.
Try it
Build it
Mount the player as usual, keep its controller, and mark terms with data-mk-step. Use buttons, not spans, so the terms are reachable without a mouse.
page.html
<p>The <button data-mk-step="0">home hub</button> switches the
<button data-mk-step="1">lights</button> …</p>
<div id="home"><!-- server-rendered final frame --></div>
<script type="module">
import { mountPlayer } from "./motion-kit/runtime/player.mjs";
const player = mountPlayer(home, scene);
for (const term of document.querySelectorAll("[data-mk-step]")) {
const go = () => player.seekStep(Number(term.dataset.mkStep));
term.addEventListener("pointerenter", go);
term.addEventListener("focus", go);
term.addEventListener("click", go);
}
</script>seekStep(i)jumps to a settled frame without animating, so the diagram never shows a half-drawn state.- Never hover-only: touch has no hover, so the same handler runs on focus and click.
- Marking the term back from the diagram needs the active step. This page polls
controller.timeagainst the scene’s steps: needs: player onStep event (#9). - Reduced motion changes nothing here: jumps are already instant.
Then: make it explorable
A control can change the spec itself. The parameter is input, not state: the page re-creates the scene and seeks the same step, so every frame is still a pure function of t.
slider.oninput = () => {
const step = stepIndexAt(scene, player.time); // keep the reader’s place
const spec = { ...base, spokes: base.spokes.slice(0, slider.value) };
scene = createScene(spec, { format });
player = mountPlayer(el, scene, { autoplay: "none" });
if (step < 0) player.seek(0); // before the first step
else player.seekStep(Math.min(step, scene.steps.length - 1));
};Reading the current step needs a getter: needs: controller.step getter.