Preloader

Preloader orchestrates a rapid horizontal slide of an image strip across the screen. As the sequence decelerates, the surrounding images scale down while the central "hero" image expands from a thumbnail to fill the entire viewport, creating a seamless transition into the main interface.


Installation

Install the component

Run the following command to install the component and its dependencies:
npx @motion-core/cli add preloader

Import the component

Import the component into your Svelte file:
import { Preloader } from "$lib/motion-core";
import { Preloader } from "$lib/motion-core";

Usage

<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="h-8 gap-1.5 rounded-md border border-border bg-card px-3 text-xs font-medium tracking-wide text-foreground uppercase shadow-sm"
	>
		Trigger Preloader
	</button>

	{#if showPreloader}
		<div use:portal>
			<Preloader
				class="bg-card"
				{images}
				onComplete={() => (showPreloader = false)}
			/>
		</div>
	{/if}
</div>

Props

Preloader

PropTypeDefault
images
{src: string, alt?: string}[]
class
string ""
onComplete
() => void undefined