Fan Carousel Free React component
Image cards hinged on one shared axis, fanned out like the pages of an open book and spinning slowly in 3D. Drag sideways to spin it yourself. Pure CSS 3D, no WebGL.
Get the code
npx shadcn@latest add https://alphenex.com/r/fan-carousel.jsonWorks with any React project through the shadcn CLI. Prefer to paste it yourself? Copy the two files below into components/alphenex/. No Tailwind or animation library needed.
import FanCarousel from '@/components/alphenex/fan-carousel';
<FanCarousel images={[{ src: '/work-1.jpg', alt: 'Project one' }, /* ... */]} />'use client';
import { useEffect, useRef } from 'react';
import './fan-carousel.css';
/**
* FanCarousel
* Image cards hinged on one shared axis, fanned out like the pages of an
* open book and spinning slowly in 3D. Drag sideways to spin it yourself.
*
* Free from Alphenex Lab: https://alphenex.com/lab/fan-carousel (MIT)
*/
export default function FanCarousel({
images = [], // [{ src, alt }]
cardWidth = 180,
cardHeight = 240,
speed = 18, // spin in degrees per second
tilt = 18, // forward tilt of the axis in degrees
className = '',
style,
...props
}) {
const rotorRef = useRef(null);
useEffect(() => {
const rotor = rotorRef.current;
if (!rotor) return undefined;
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let angle = -20;
let velocity = 0;
let dragging = false;
let lastX = 0;
let last = performance.now();
let frame = 0;
const loop = (now) => {
const dt = Math.min(0.05, (now - last) / 1000);
last = now;
if (!dragging) {
velocity *= 0.95;
angle += (reduce ? 0 : speed * dt) + velocity;
}
rotor.style.transform = `rotateX(${-tilt}deg) rotateZ(${tilt * 0.6}deg) rotateY(${angle}deg)`;
frame = requestAnimationFrame(loop);
};
const down = (e) => {
dragging = true;
lastX = e.clientX;
velocity = 0;
};
const move = (e) => {
if (!dragging) return;
const dx = e.clientX - lastX;
lastX = e.clientX;
angle += dx * 0.4;
velocity = dx * 0.4;
};
const up = () => {
dragging = false;
};
frame = requestAnimationFrame(loop);
const stage = rotor.parentElement;
stage.addEventListener('pointerdown', down);
window.addEventListener('pointermove', move, { passive: true });
window.addEventListener('pointerup', up);
return () => {
cancelAnimationFrame(frame);
stage.removeEventListener('pointerdown', down);
window.removeEventListener('pointermove', move);
window.removeEventListener('pointerup', up);
};
}, [speed, tilt]);
const step = 360 / Math.max(1, images.length);
return (
<div
className={`alx-fan ${className}`}
style={{ '--alx-fan-w': `${cardWidth}px`, '--alx-fan-h': `${cardHeight}px`, ...style }}
{...props}
>
<div ref={rotorRef} className="alx-fan__rotor" role="list" aria-label="Image carousel">
{images.map((image, i) => (
<figure key={image.src + i} className="alx-fan__card" role="listitem" style={{ transform: `rotateY(${i * step}deg)` }}>
<img src={image.src} alt={image.alt || ''} draggable="false" loading="lazy" decoding="async" />
</figure>
))}
</div>
<span className="alx-fan__shadow" aria-hidden="true" />
</div>
);
}
/* FanCarousel, Alphenex Lab (MIT) */
.alx-fan {
position: relative;
display: grid;
place-items: center;
width: calc(var(--alx-fan-w) * 2.4);
max-width: 100%;
height: calc(var(--alx-fan-h) * 1.6);
perspective: 1100px;
cursor: grab;
touch-action: pan-y;
user-select: none;
}
.alx-fan:active {
cursor: grabbing;
}
.alx-fan__rotor {
position: relative;
width: 0;
height: var(--alx-fan-h);
transform-style: preserve-3d;
will-change: transform;
}
/* Each card is hinged on its left edge, which sits on the shared axis. */
.alx-fan__card {
position: absolute;
left: 0;
top: 0;
width: var(--alx-fan-w);
height: var(--alx-fan-h);
margin: 0;
overflow: hidden;
border-radius: 6px;
transform-origin: 0 50%;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.alx-fan__card img {
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: none;
}
.alx-fan__shadow {
position: absolute;
bottom: 4%;
left: 50%;
width: calc(var(--alx-fan-w) * 1.6);
height: 26px;
border-radius: 50%;
background: radial-gradient(closest-side, rgba(0, 0, 0, 0.28), transparent);
transform: translateX(-50%);
pointer-events: none;
}
Paste this into Claude, ChatGPT, Cursor, Lovable or v0 to build it from scratch.
Build a React "FanCarousel" with plain CSS 3D. A container with perspective: 1100px holds a zero-width "rotor" with transform-style: preserve-3d. Each image card is absolutely positioned with transform-origin at its left edge and rotateY(index × 360 / count), so all cards hinge on the same vertical axis like book pages. Spin the rotor with requestAnimationFrame (rotateX(−tilt) rotateZ(tilt × 0.6) rotateY(angle)), and let horizontal dragging rotate it with momentum. Add a soft elliptical shadow underneath. Props: images, cardWidth, cardHeight, speed, tilt.How the fan carousel works
All cards hang from one vertical line. Each one is rotated around its own left edge by an equal share of 360 degrees, so together they open up like the pages of a book stood on its spine.
The parent keeps the 3D space with transform-style: preserve-3d, and one loop rotates it around the axis, tilted forward and sideways so you see the fan from an angle.
Dragging adds to the rotation and leaves momentum that eases back to the normal spin. A blurred ellipse underneath grounds it.
Frequently asked questions
Want motion like this on your website?
We design and build custom websites with motion, 3D and SEO built in. Websites from $500.