182

Flip-Through Gallery

£7
or the whole Vault, £99
Open in new tab

A photo gallery you flip through: around fifty photographs stand on a horizontal axis seen slightly from above, and scrolling, dragging or the arrow keys tip each one over the top so it falls forward onto the turned stack with weight and a small bounce, with section buttons that jump the short way round.

advanced
9 more details
3d-transformsdragtouch-dragmomentumspring-physicsinfinite-loopkeyboard-navigationlightboxprogressive-enhancement

Released

About this effect

Your photographs stand in a stack on a horizontal axis, seen slightly from above in real perspective. The photo at the front faces you; the edges of the photos still to come show above it, and the photo you just turned past lies forward below, foreshortened and slightly dimmed, so the frame is photographs top and bottom with nothing else around them. A quiet column beside the stack gives the count, the caption and an optional detail line, with the sections listed above.

Read the full effect overview

Turn the stack with the scroll wheel, a drag or the arrow keys. A photo lifts, tips over the top and falls forward with weight, speeding up as it passes upright and landing on the turned stack with a small bounce. It stays recognisable through the fall and only dims in the last few degrees before it goes edge-on. Drag slowly and you can hold a photo balanced mid-turn and move it back and forth with your finger. Flick hard and a dozen photos riffle over at once, each a beat behind the last, before the run slows and stops exactly on one. The stack never ends: after the last photo comes the first.

The section buttons jump straight to a section by the shorter way round. Click or press Enter on the front photo and its full-size file opens in a viewer.

Flip-Through Gallery - GSAP animation effect preview

What's included

16 items
  • A stack of photographs on a horizontal axis in real 3D perspective: the front photo upright, the edges of the next ones behind it, the turned photo lying forward below
  • Each photo tips over the top and falls with weight, accelerating past upright and landing on the turned stack with a small damped bounce
  • Photographs edge to edge with no frame or mount; the photo you just passed shows on the turned stack, slightly dimmed so the front photo stays brightest
  • Photos stay readable through the fall and darken only in the last degrees before they turn edge-on
  • Slow drags hold a photo balanced mid-turn and follow your finger both ways
  • Hard flicks riffle a dozen photos at once, staggered through the turn, with momentum that settles exactly on one
  • Scroll wheel, mouse drag, touch drag and arrow keys all turn it; Page Up and Page Down jump five
  • Endless: the last photo leads straight back to the first
  • Section buttons jump to a section the shorter way round; the current one is marked in ink
  • A quiet caption line with the count, the caption and an optional detail line such as a date or place
  • Click, tap or Enter on the front photo opens its full-size file in a viewer; every photo stays a real link to that file
  • Thumbnails load front first, a few at a time, with retries; full-size files load only when a photo is opened
  • Only the photos turning at that moment are animated; the rest stay still until they are needed
  • Reduced motion and no JavaScript both show a plain grid of linked photos with captions
  • View angle, packing, start photo and sensitivity from data attributes; size, corners and type are plain CSS
  • Small API (goTo, next, prev, open, refresh, revert) with change and open events; several galleries on a page stay independent

Perfect for

4 use cases
  • Photography portfolios and archives that want browsing to feel like flicking through a stack of prints
  • Travel, food and design journals with a large collection grouped into places or subjects
  • Studio and shop sites showing a catalogue of objects, materials or projects one photo at a time
  • Event and wedding galleries where visitors riffle through dozens of moments and open the ones they like

How it works

2 sections

The gallery is an ordinary ordered list. Each item is a link to a full-size photograph wrapping a small thumbnail, a caption and a number, with optional attributes for its section and a detail line. Without JavaScript, or with reduced motion, that list shows as a grid and nothing else happens.

With JavaScript the same photos are placed in CSS 3D on a horizontal axis, and one number, the position of the stack, decides where every photo should be. Scrolling, dragging and the keys move that number, and GSAP eases it to a stop on a whole photo after a flick or a section jump. Each photo that is turning follows its target angle like a weighted object, so it can lag, fall and bounce on its own, while the resting photos keep still. Everything the script adds, from the far sides of the photos to the caption line, viewer and listeners, is removed again on revert().

Difficulty Advanced
Includes HTML + JS + CSS source, documentation, AI setup prompt, lifetime updates

Lighthouse, as measured

Google Lighthouse on this effect's demo, from the latest scan. A measurement of the demo as shipped, not a promise for your page.

Accessibility
100
Best practices
100

No performance score, on purpose. That figure depends on how you deploy: your server's compression and caching, your CDN, the connection and the device doing the test, none of which the code controls. The same page can score very differently on two consecutive runs, so measure it where it will live.

The Vault opens this source and the whole library.

Each product gives you the HTML, CSS and JavaScript source, the full documentation and an AI setup prompt, licensed for unlimited personal and commercial projects. Every paid product is tested for desktop and mobile layouts, reduced-motion handling, animation cleanup and keyboard controls wherever there is something to operate.

One payment, over 350 products, and future additions to the library.

Documentation

Quick Start

1. Add to your HTML <head>:

In your downloadThe working code for this step, in index.html.

2. Add before the closing </body> tag:

In your downloadThe working code for this step, in index.html.

3. Add the gallery anywhere in your <body>:

In your downloadThe working code for this step, in index.html.

Each item is a link to the full-size photograph wrapping a small 16:9 thumbnail. Photos with the same data-section form a section in the bar. data-detail is an optional second caption line, such as a date, place or roll and frame. Around 30 to 80 photos suit the stack; it needs at least 6.

Using It With Your Own Design

What the effect needs from your markup:

  • A wrapper with data-flip-gallery, holding a data-flip-gallery-stage element, holding the data-flip-gallery-cards list. The stage is the area that takes drags and the scroll wheel.
  • Each list item has the class flip-gallery__card and one .flip-gallery__link inside it. The link's href is the full-size file, which loads only when the photo is opened. The <img> inside is the thumbnail.
  • .flip-gallery__caption and .flip-gallery__num are read for the caption line, the viewer and the screen reader announcement. Without them the image's alt text and the photo's position are used. While the stack is live they stay in the link for screen readers but are hidden visually; the caption line shows them instead.
  • data-section and data-detail are optional. Without sections there are no section buttons.
  • The script appends the caption line and section buttons to the wrapper (when the gallery is at least 980px wide the sections sit in the left margin and the caption in the right; narrower, both go under the stack) and a <dialog> for the full-size viewer to <body>.
  • The script takes over loading the thumbnails while the stack is live, front photos first and a few at a time, and puts every src back on revert().

What is only the demo's styling: the demo page block at the top of style.css (ground colour, centred shell, the cue line), the font, the caption and button type, and the corner radius (--flip-radius). The grid layout used without JavaScript is plain CSS grid and can be restyled freely.

CSS the effect depends on:

  • The size variables set on .flip-gallery inside the .has-js block: --card-w, --card-h, --hub and --reach. Change --card-w to size the stack (it already fits the gallery width and the viewport height); keep --card-h at the thumbnails' shape.
  • transform-style: preserve-3d on .flip-gallery__tilt, .flip-gallery__cards and .flip-gallery__card, and backface-visibility: hidden on the link and .flip-gallery__back. Without these the stack flattens or shows photos through each other.
  • transform-origin on .is-live .flip-gallery__card: it puts each photo's axis --hub below its foot.
  • will-change: transform on the photos. Removing it makes the browser repaint every photo at a new size on each frame of a turn.
  • The pre-hide: with .has-js the stack's space is reserved from the first paint and the photos stay hidden until the script adds .is-live. If GSAP fails to load the script removes .has-js and the plain grid shows.
  • touch-action: none on the stage, so a vertical drag on the stack turns it instead of scrolling. Drags that start anywhere else still scroll the page.

Options

Set these on the data-flip-gallery element.

Attribute Values Default Description
data-start Photo index from 0 0 The photo that faces you when the gallery opens
data-intro true, false true Riffle the last few photos over on load to show how the stack moves
data-tilt 10 to 50 (degrees) 24 How far above the stack you look from
data-spacing 1.5 to 8 (degrees) 3.4 How tightly the photos behind the front one pack
data-sensitivity 0.25 to 4 1 Photos turned per pixel of drag or scroll. Higher turns more photos for the same gesture
data-wheel true, false true Let the scroll wheel turn the photos while the pointer is over the stack

On each photo: data-section (section name) and data-detail (second caption line), both optional.

How the stack takes input

The gallery is self-contained: it never pins or takes over the page. The scroll wheel turns the photos only while the pointer is over the stack, and a scroll that started somewhere else and drifts across the stack keeps scrolling the page, so the page is never trapped. The stack is endless, so there is no end to scroll through. On touch screens a vertical drag on the stack turns it; a drag that starts outside it scrolls the page as normal.

Accessibility

  • Links stay links. Every photo is a real link to its full-size file, named by its image's alt text and caption. Ctrl, Cmd or Shift-click opens the file the browser's own way.
  • Keyboard. Only the front photo is in the tab order. Arrow keys turn one photo at a time (hold one to riffle), Page Up and Page Down move five, Home and End go to the first and last photo, and Enter or Space opens the front photo. Focus follows the front photo as it changes.
  • Sections. The section buttons are a labelled group with aria-pressed on the current section.
  • Screen readers. After the stack settles, a polite live region announces the position, section and caption, for example "12 of 50. Coast. Heather above the sea". The front photo is described by a short hint on how to use the keys. Photos turned out of sight stay in the accessibility tree.
  • Viewer. A native <dialog>: Escape, the Close button or a click on the backdrop closes it, and focus returns to the photo.
  • Touch. A vertical drag on the stack turns it; a tap on the front photo opens it and a tap on another photo turns to it.
  • Reduced motion. With prefers-reduced-motion: reduce the script builds nothing and the photos show as a plain grid of linked photos with captions. Switching the setting while the page is open rebuilds or removes the stack.
  • No JavaScript, or a blocked CDN. The same plain grid of links.

Photographs

The demo's 50 photographs are cropped, resized derivatives of Pexels and Unsplash photos used under those sites' free licences; assets/img-manifest.json lists each output file and its size. Thumbnails are 600 × 338 WebP; full-size files are 1600 px wide. Replace the files with your own, or edit the manifest and rebake them.

Dependencies

Required:

  • GSAP 3.12+ (the demo is built against 3.15.0). Core only, no plugins.

Not used: ScrollTrigger and Lenis. The stack takes its own input and does not depend on page scrolling, so it sits happily on a page that runs either.

Also in your download: the full source, worked examples, the events and programmatic API, and the class reference.

£7