# SvelteKit

Load the rupa-player element in onMount so server rendering keeps your text and the player starts in the browser.

## Quick start

1. Install the player.

   ```sh
   npm i @rupamotion/player
   ```

2. Put `hero.rupaplay` (export as **Player file** in Rupamotion) in `static/`.

3. Load the element in `onMount`, so server rendering keeps your text and the player starts in the browser:

   ```svelte
   <script>
   	import { onMount } from "svelte";
   	onMount(() => import("@rupamotion/player/element"));
   </script>

   <rupa-player src="/hero.rupaplay"></rupa-player>
   ```

That's it: the animation plays.

## Need control?

The element's `player` is the player once the file is mounted (`null` before). Bind the element with `bind:this`
(Svelte 5 syntax; Svelte 4 writes `on:click`):

```svelte
<script>
	import { onMount } from "svelte";
	onMount(() => import("@rupamotion/player/element"));

	let hero;
</script>

<rupa-player bind:this={hero} src="/hero.rupaplay"></rupa-player>
<button onclick={() => hero?.player?.pause()}>Pause</button>
```

See [Control playback](/guides/control/) and [Events](/guides/events/).
