Each case study sticks near the top as you scroll and the next one slides over it, while the ones underneath shrink back. Works on the page or inside a box.
How to use
Make two files in your project's components folder: stacking-cards.tsx and stacking-cards.module.css.
Paste the code into each one, keeping the licence note at the top of the component.
It needs nothing beyond React. Your project needs CSS Modules, which Next.js and Vite already have.
Import it where you want it, then change the words, colours and sizes to yours.
The code
"use client";
import { createContext, type HTMLAttributes, type PropsWithChildren, type RefObject, useCallback, useContext, useEffect, useRef } from "react";
import styles from "./stacking-cards.module.css";
type StackingCardsContextType = { register: (index: number, el: HTMLElement | null) => void };
const StackingCardsContext = createContext<StackingCardsContextType | null>(null);
function useStackingCardsContext() {
const context = useContext(StackingCardsContext);
if (!context) throw new Error("StackingCardItem must sit inside StackingCards");
This comes with paid plans
The code for every component comes with paid plans, along with the rest of the AI toolkit. The first component under each heading is free.