Scroll Progress

PreviousNext

Animated Scroll Progress for your pages

Docs
magicuiui

Preview

Loading preview…
registry/magicui/scroll-progress.tsx
"use client"

import { motion, MotionProps, useScroll } from "motion/react"

import { cn } from "@/lib/utils"

interface ScrollProgressProps extends Omit<
  React.HTMLAttributes<HTMLElement>,
  keyof MotionProps
> {
  ref?: React.Ref<HTMLDivElement>
}

export function ScrollProgress({
  className,
  ref,
  ...props
}: ScrollProgressProps) {
  const { scrollYProgress } = useScroll()

  return (
    <motion.div
      ref={ref}
      className={cn(
        "fixed inset-x-0 top-0 z-50 h-px origin-left bg-gradient-to-r from-[#A97CF8] via-[#F38CB8] to-[#FDCC92]",
        className
      )}
      style={{
        scaleX: scrollYProgress,
      }}
      {...props}
    />
  )
}

Installation

npx shadcn@latest add @magicui/scroll-progress

Usage

import { ScrollProgress } from "@/components/ui/scroll-progress"
<ScrollProgress />