Scroll Motion Gallery
A dynamic gallery where images rotate and move with scroll using GSAP ScrollTrigger, creating depth and motion. Hover interactions reveal video previews and metadata, enhanced with a subtle Framer Motion parallax effect. ✨

If you face any issues, refer to the working source code provided.
Initializing the project
Start by creating a new Next.js application and install the required dependencies:
We'll also use Sass for styling if you prefer (optional).
Component structure
The gallery consists of a main `ScrollGallery` component that renders a container with absolute‑positioned `ParallaxImage` components. Each image gets its position and rotation values from a central `layoutData` array.
Layout and asset data
Each image is placed using absolute positioning with `vw` and `vh` units. The `layoutData` array defines the coordinates and rotation angles. The rotation smoothly changes from `rotate` (when the image enters) to `rotateTo` (when centered) and then to a fraction of the original as it leaves.
Asset details (image/video paths, label, duration) are stored in a separate `assetData.ts` file. A helper `getAsset` retrieves the data for a given ID. Here's a minimal example:
Core animations
Each `ParallaxImage` combines two animation techniques:
**GSAP + ScrollTrigger** for rotation – we create two tweens that update based on scroll position, from entry to center and from center to exit.
**Framer Motion** for parallax – we use `useScroll` and `useTransform` to shift the image vertically based on scroll progress, smoothed with `useSpring`.
Hover interactions reveal video previews and metadata by toggling opacity and scaling the image. A simple `useState` toggles the hover state, and CSS transitions handle the visuals.
Adding smooth scrolling with Lenis
To give the gallery a buttery‑smooth feel, we'll integrate Lenis, a lightweight smooth scroll engine. Create a provider component that initializes Lenis and wraps your application.
Now wrap your root layout with this provider to enable smooth scrolling everywhere:
GSAP ScrollTrigger works seamlessly with Lenis – no extra configuration needed. The scroll‑based animations will now be driven by Lenis's smooth scroll, creating a cohesive experience.
Using the component
Simply import `ScrollGallery` into any page (make sure it's a client component). The gallery will fill the available width and create a long scrollable area.
