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

<script lang="ts">
	import {
		InfinitePhysicsGallery,
		type InfinitePhysicsGalleryItem,
	} from "motion-core";

	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",
			},
		},
	];
</script>

<InfinitePhysicsGallery
	class="h-full min-h-160 w-full"
	{items}
	cellWidth={280}
	cellHeight={360}
	gap={20}
	cellClass="rounded-md"
	friction={0.95}
	scrollSettings={{
		wheelSpeed: 1.4,
		friction: 0.94,
		edgeThreshold: 120,
		edgeScrollSpeed: 1.6,
	}}
/>

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