Parallax Image Gallery

A visually stunning image gallery with multi-layer parallax scrolling. Images move at different speeds to create depth. Features include smooth scrolling, scroll-triggered reveal animations, lazy loading, and a built-in lightbox modal.


Parallax Image Gallery


Build an immersive photo gallery with a multi-layer parallax effect. As users scroll, images translate at varying speeds, creating a sense of 3D depth and movement. This snippet combines modern CSS Grid layouts with vanilla JavaScript for performance-focused animations.

Features

Implementation Guide

The core effect is achieved by updating the transform: translateY() property of each image based on the scroll position and its assigned speed factor.

// Parallax Logic
window.addEventListener('scroll', () => {
  let scrollY = window.scrollY;
  
  items.forEach((item) => {
    let speed = item.getAttribute('data-speed');
    // Calculate movement based on scroll position and speed
    let movement = (scrollY * speed) / 10; 
    
    // Apply transform only when element is in view for performance
    if (isInViewport(item)) {
       item.style.transform = `translateY(${movement}px)`;
    }
  });
});

CSS Grid Structure

The gallery uses a 12-column CSS Grid for flexible and creative image placement.

.parallax-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 2rem;
}

/* Custom placement for variety */
.item-1 { grid-column: span 6; height: 600px; }
.item-3 { grid-column: 2 / span 5; margin-top: -50px; }

Use this snippet to showcase portfolios, photography, or product collections in a way that feels dynamic and alive.