Baktiyar Ablaikhan

Scroll Progress

Source
Magic UI ↗
Author
Magic UI
Licence
MIT

Loading…

A gradient bar along the top fills as you scroll the panel.

Code

"use client";

import { useRef } from "react";

import { ScrollProgress } from "@/lab/magicui/ui/scroll-progress";

export default function ScrollProgressDemo() {
  const ref = useRef<HTMLDivElement>(null);
  return (
    <div className="relative h-full w-full">
      <ScrollProgress container={ref} className="h-1" />
      <div ref={ref} className="h-full w-full overflow-y-auto px-[8%] py-8 text-neutral-800">
        <h2 className="pb-4 text-xl font-bold">Scroll inside this card.</h2>
        {Array.from({ length: 8 }, (_, i) => (
          <p key={i} className="mb-4 text-sm leading-relaxed text-neutral-600">
            The bar along the top edge tracks how far this panel has been scrolled. It is a single
            motion div whose scaleX follows scrollYProgress, bound here to the card&apos;s own scroll
            container rather than the page.
          </p>
        ))}
      </div>
    </div>
  );
}
Prompt

Build "Scroll Progress", a scroll animation. What it does: A gradient bar along the top fills as you scroll the panel. Write it as a single self-contained React component in TypeScript that fills its parent (w-full h-full), styled with Tailwind CSS, using motion. Technique: the Motion library. It sits on a light background, in a 16:10 frame. Respect prefers-reduced-motion with a still state, pause work when the element is off screen, and keep it accessible. Original: https://magicui.design/docs/components/scroll-progress (Magic UI, MIT).