Installation
Install the component
Run the following command to install the component and its dependencies:
npx @motion-core/cli add preloaderImport the component
Import the component into your Svelte file:
Transition
A kinetic loading sequence that decelerates an image strip before scaling the hero asset to full screen.
npx @motion-core/cli add preloaderimport { Preloader } from "$lib/motion-core";import { Preloader } from "$lib/motion-core";<script lang="ts">
import { Preloader } from "motion-core";
const images = [
{
src: "/images/demos/sample-1.jpg",
alt: "Alt 1",
},
{
src: "/images/demos/sample-2.jpg",
alt: "Alt 2",
},
{
src: "/images/demos/sample-6.jpg",
alt: "Alt 3",
},
{
src: "/images/demos/sample-4.jpg",
alt: "Alt 4",
},
{
src: "/images/demos/sample-5.jpg",
alt: "Alt 5",
},
];
let showPreloader = $state(false);
function startPreloader() {
showPreloader = true;
}
function portal(node: HTMLElement) {
document.body.appendChild(node);
return {
destroy() {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
},
};
}
</script>
<div class="flex flex-col items-center justify-center">
<button
onclick={startPreloader}
class="card h-8 gap-1.5 rounded-sm bg-background-muted px-3 text-xs font-medium tracking-wide text-foreground uppercase"
>
Trigger Preloader
</button>
{#if showPreloader}
<div use:portal>
<Preloader
class="bg-background"
{images}
onComplete={() => (showPreloader = false)}
/>
</div>
{/if}
</div>
| Prop | Type | Default |
|---|---|---|
images | {src: string, alt?: string}[] | — |
class | string | "" |
onComplete | () => void | undefined |