Control playback
Copy as MarkdownEvery export that plays with the player (an interactive flow, or a clip with the player loaded) has its player on its
root, root.rupa:
const hero = document.querySelector(".hero").rupa;hero.play("hover"); // a state: one of the clips of the scenehero.pause();hero.seek(500); // mshero.setSpeed(0.5); // hero.speed reads ithero.on("statechange", (event) => console.log(event.state));A single clip runs on CSS alone. Load the player on the page (@rupamotion/player or the CDN line) to control it.
Try it: each control below runs the line the code panel shows.
Oct 14–15 · Lisbon & online
Kinetic Summit 2027
Two days of motion, interfaces and the people who build them.
A
M
J
K
import { mount } from "@rupamotion/player";
const player = mount(document.querySelector(".event-hero"));
player.play("drift"); The Player object
Section titled “The Player object”interface Player<S extends string = string> { readonly root: Element; readonly state: S | null; // the state that plays readonly states: readonly S[]; readonly time: number; // ms since this state began readonly duration: number | null; // length of the chain of the state; null when it has no end readonly paused: boolean; readonly speed: number; setSpeed(speed: number): void; // 1e-6 to 1e6 play(state?: S | null): void; // no argument: go on; a state: start it from 0 pause(): void; seek(ms: number): void; // clamped to [0, duration] on( type: "statechange" | "complete" | "play" | "pause" | "error", listener: (event: PlayerEvent<S>) => void, ): () => void; destroy(): void;}Good to know
Section titled “Good to know”root.rupais the player. A secondmounton the same root returns the same object.destroy()lets go of the root at once (root.rupa = 0), even from a listener, so amountafter it makes a new player. Call it when you take a root out of the page (<rupa-player>and<RupaPlayer>do it for you).- The player drives only the CSS animations of its export. A transition or
animate()of your own inside the root, and a root nested in it, are left alone. - Pausing freezes the run. Any state change plays again, and the speed carries to every later state.
play(state)(ordata-rupa-stateset from your code) of a state a trigger plays starts it as if that trigger fired: a card flipped withplay("flip")flips back on the next click, to what played before.- A wrong call (
setSpeed(0),seek(NaN), an unknown state) throws aRangeErrororTypeErrorat your line. Events, timers and file loads never throw. - Without JavaScript, the DOM attribute
data-rupa-statestill sets the state, and the root sendsrupastatechange.