React Grid Motion Background
React grid motion background with GSAP animation. Features mouse-responsive grid movement, customizable content items, and smooth inertia-based parallax effects.
Creating interactive grid animations?
Join our Discord community for help from other developers working with GSAP animations and motion design.
Ever watched a grid of elements dance and flow in response to your mouse movement, creating that mesmerizing parallax effect that makes interfaces feel alive and responsive? The way each row moves with different speeds and directions, creating depth and dimension that transforms flat layouts into dynamic, three-dimensional experiences? Most grid layouts are static, predictable, and lack the organic responsiveness that makes user interactions feel magical. This React component creates that captivating grid motion effect with GSAP animations, customizable content, and smooth inertia-based movement that responds naturally to mouse input.
Interactive grid with mouse-responsive parallax
Watch grid elements flow with alternating directional movement and smooth inertia effects:
Built for React applications with TypeScript and Next.js. Uses GSAP for high-performance animations with hardware acceleration and optimized ticker system. Mathematical inertia calculations create natural movement patterns while customizable grid layouts support any content type. Perfect for hero sections, portfolio showcases, or any interface needing sophisticated interactive backgrounds.
Installation
npx shadcn@latest add https://www.shadcn.io/registry/grid-motion-background.json
npx shadcn@latest add https://www.shadcn.io/registry/grid-motion-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/grid-motion-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/grid-motion-background.json
Why static grids feel lifeless
Developers create CSS grids with hover effects and consider them interactive. Maybe they add a simple transform that scales on hover. The problem? Static layouts can't capture the organic, responsive nature of truly interactive designs that make users want to explore and engage.
Grid motion backgrounds with GSAP physics change everything. They tap into our fascination with parallax and depth—the way objects at different distances move at different speeds, how layers create the illusion of three-dimensional space. The animation calculations use mathematical inertia and easing functions to generate natural, physics-based movement.
This component handles complex animation mathematics automatically. GSAP ticker optimization, inertia calculations, alternating directional flow, and smooth easing curves all work together seamlessly. The result feels like controlling a living, breathing grid that responds to your every movement.
Features
- GSAP-powered animations with hardware acceleration and optimized ticker system
- Mouse-responsive parallax with real-time coordinate tracking and smooth interpolation
- Alternating row directions creating natural parallax depth and visual rhythm
- Customizable grid layout supporting any number of rows and columns
- Content flexibility supporting text, emojis, images, or custom React elements
- Inertia-based movement with mathematical easing for natural, physics-based motion
- Gradient backgrounds with customizable radial gradient overlays
- Rotation controls for angled grid presentations and dynamic compositions
- Performance optimization with GSAP lag smoothing and efficient rendering
- TypeScript support with complete prop forwarding and type safety
API Reference
GridMotionBackground
Prop | Type | Default | Description |
---|---|---|---|
items | string[] | [] | Array of content items (text, emojis, URLs) |
gradientColor | string | "black" | Center color for radial gradient overlay |
maxMoveAmount | number | 300 | Maximum pixel movement for parallax effect |
baseDuration | number | 0.8 | Base animation duration in seconds |
gridRows | number | 4 | Number of grid rows |
gridCols | number | 7 | Number of grid columns |
rotation | number | -15 | Grid rotation angle in degrees |
className | string | - | Additional CSS classes |
...props | HTMLAttributes<HTMLDivElement> | - | All standard div props |
Grid Configurations
Different grid layouts for various use cases:
Rows | Cols | Total Items | Aspect | Use Case |
---|---|---|---|---|
3 | 5 | 15 | Compact | Mobile-friendly layouts |
4 | 7 | 28 | Standard | Balanced desktop display |
5 | 9 | 45 | Extended | Large screen showcases |
6 | 4 | 24 | Vertical | Portrait-oriented designs |
Content Types
The component supports various content formats:
Format | Example | Rendering |
---|---|---|
Text | "Hello World" | Centered text display |
Emojis | "🚀" | Large emoji display |
Image URLs | "https://..." | Background image cover |
Numbers | "123" | Formatted text display |
Animation mathematics
Inertia Calculation: Uses alternating direction multipliers with mathematical easing curves to create natural parallax movement that varies by row for depth illusion.
Mouse Tracking: Normalizes mouse coordinates to 0-1 range, then applies movement calculations with configurable maximum displacement for consistent behavior across screen sizes.
GSAP Ticker Optimization: Utilizes GSAP's optimized ticker system with lag smoothing disabled for consistent 60fps performance and smooth animation updates.
Easing Functions: Implements "power3.out" easing curves for natural deceleration that mimics real-world physics and creates satisfying motion feel.
Performance considerations
GSAP Ticker: Uses GSAP's optimized ticker instead of requestAnimationFrame for better performance and consistency across devices.
Lag Smoothing: Disables GSAP lag smoothing to prevent animation jumps during performance drops, maintaining smooth visual experience.
Transform Optimization: Uses CSS transforms exclusively for movement, enabling hardware acceleration and GPU rendering for smooth animations.
Grid Size Impact: Larger grids (more rows/columns) require more DOM elements and animation calculations. Consider reducing grid size on mobile devices.
Common gotchas
Item Array Length: If fewer items than grid slots are provided, remaining slots show default "Item N" text. Ensure your items array matches the grid size.
Image URL Detection: Component detects image URLs by checking if string starts with "http". Local images need full URLs or different handling.
Mouse Coordinate System: Uses clientX coordinates which may behave differently across browsers. The component normalizes these for consistent behavior.
GSAP Dependencies: Requires GSAP library to be installed. Component will fail silently if GSAP is not available in the bundle.
Rotation Boundaries: Extreme rotation values (greater than 45 degrees) may cause grid elements to move outside viewport boundaries.
Animation Overwrite: Uses GSAP's "auto" overwrite mode to prevent animation conflicts when mouse moves rapidly.
You might also like
Interactive Grid Pattern
Mouse-responsive grid patterns with dynamic effects
Particles
Interactive particle systems with physics
Light Waves
Animated light beams with noise distortion
Balatro Background
Psychedelic spiral patterns with mouse control
Questions developers actually ask
React Grid Distortion Background
React grid distortion background with Three.js shader effects. Features mouse-responsive image warping, customizable grid density, and fluid distortion patterns for dynamic visual experiences.
React Grid Pattern Background
React grid pattern background with professional structure. Clean SVG lines and CSS masks create organized layouts with TypeScript and shadcn/ui.