JavaScript
Copy as MarkdownQuick start
Section titled “Quick start”-
Install the player.
Terminal window npm i @rupamotion/player -
Put
hero.rupaplay(export as Player file in Rupamotion) inpublic/(or wherever your build serves static files), and an empty element in the page:<div id="hero"></div> -
Mount the file into it.
markup: "auto"writes the file’s markup into the empty element:import { mountFile } from "@rupamotion/player/file";await mountFile(document.querySelector("#hero"), "/hero.rupaplay", { markup: "auto" });
That’s it: the animation plays.
This demo loads a .rupaplay file: it plays once JavaScript runs.
Need control?
Section titled “Need control?”mountFile resolves { player } or { error }. Keep the player to control it:
import { mountFile } from "@rupamotion/player/file";
const root = document.querySelector("#hero");if (root) { const { player, error } = await mountFile(root, "/hero.rupaplay", { markup: "auto" }); if (error) console.warn(error.message); else player.play();}mountFile never rejects: it resolves { player } or { error }. Call player.destroy() when you take the root out
of the page. See control playback, events and errors.