Layout

Flip Grid

A layout component that smoothly animates its children when the grid structure changes.


Installation

Install the component

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

Import the component

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

Usage

Demo 0
Demo 1
Demo 2
Demo 3

Props

0.500s
0.100s
<script lang="ts">
	import { FlipGrid, FlipGridItem } from "motion-core";

	type Props = {
		columns?: number;
		duration?: number;
		stagger?: number;
		ease?: string;
	};

	const images = [
		"/images/demos/sample-8.jpg",
		"/images/demos/sample-9.jpg",
		"/images/demos/sample-10.jpg",
		"/images/demos/sample-11.jpg",
	];

	let {
		columns = 4,
		duration = 0.5,
		stagger = 0.1,
		ease = "power2.inOut",
	}: Props = $props();
</script>

<div class="relative h-full min-h-96 w-full">
	<div class="h-full p-4">
		<FlipGrid class="w-full gap-4" {columns} {duration} {stagger} {ease}>
			{#each images as src, i (src)}
				<FlipGridItem
					id={`img-${i}`}
					class="relative aspect-square w-full overflow-hidden rounded-lg shadow-md"
				>
					<img {src} alt="Demo {i}" class="h-full w-full object-cover" />
				</FlipGridItem>
			{/each}
		</FlipGrid>
	</div>
</div>

Props

FlipGrid

PropTypeDefault
children
Snippet
columns
number undefined
class
string undefined
style
string undefined
duration
number 0.5
ease
string "power2.inOut"
stagger
number 0

FlipGridItem

PropTypeDefault
children
Snippet
id
string
class
string undefined