Showcase

Infinite Physics Gallery

A bidirectional infinite gallery with drag inertia, wheel momentum, and edge auto-scroll for image/video media.


Installation

Install the component

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

Import the component

Import the component into your Svelte file:
import { InfinitePhysicsGallery } from "motion-core";
import { InfinitePhysicsGallery } from "motion-core";

Usage

Props

280
360
20
0.950
1.400
120
1.600
<script lang="ts">
	import {
		InfinitePhysicsGallery,
		type InfinitePhysicsGalleryItem,
	} from "motion-core";

	type Props = {
		cellWidth?: number;
		cellHeight?: number;
		gap?: number;
		friction?: number;
		wheelSpeed?: number;
		edgeThreshold?: number;
		edgeScrollSpeed?: number;
	};

	const items: InfinitePhysicsGalleryItem[] = [
		{
			id: "img-1",
			type: "image",
			image: {
				src: "/images/demos/sample-1.jpg",
				alt: "Alt 1",
			},
		},
		{
			id: "img-2",
			type: "image",
			image: {
				src: "/images/demos/sample-4.jpg",
				alt: "Alt 2",
			},
		},
		{
			id: "img-3",
			type: "image",
			image: {
				src: "/images/demos/sample-10.jpg",
				alt: "Alt 3",
			},
		},
		{
			id: "img-4",
			type: "image",
			image: {
				src: "/images/demos/sample-12.jpg",
				alt: "Alt 4",
			},
		},
	];

	let {
		cellWidth = 280,
		cellHeight = 360,
		gap = 20,
		friction = 0.95,
		wheelSpeed = 1.4,
		edgeThreshold = 120,
		edgeScrollSpeed = 1.6,
	}: Props = $props();
</script>

<InfinitePhysicsGallery
	class="h-full min-h-160 w-full"
	{items}
	{cellWidth}
	{cellHeight}
	{gap}
	cellClass="rounded-md"
	{friction}
	scrollSettings={{
		wheelSpeed,
		friction,
		edgeThreshold,
		edgeScrollSpeed,
	}}
/>

Props

InfinitePhysicsGallery

PropTypeDefault
items
InfinitePhysicsGalleryItem[] []
cellWidth
number 320
cellHeight
number 400
gap
number 24
friction
number 0.95
cellClass
string ""
scrollSettings
ScrollSettings Default Scroll Settings
class
string ""

ScrollSettings

KeyTypeDefault
wheelSpeed
number 2
friction
number 0.95
edgeThreshold
number 100
edgeScrollSpeed
number 2

InfinitePhysicsGalleryItem

KeyTypeDefault
id
stringnumber undefined
type
"image""video"
image.src
string required for image items
image.alt
string undefined
video.src
string required for video items