Scroll Progress Bar
Scroll Progress Bar is a React and Tailwind CSS marquee component from Motion Primitives, licensed MIT. Copy it and paste it into your project.
Motion Primitives
MIT
marquee
What it is
Scroll Progress Bar is a React and Tailwind CSS marquee component from Motion Primitives, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i motion
Licence
This component comes from Motion Primitives and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Scroll Progress Bar
'use client';
import { motion, SpringOptions, useScroll, useSpring } from 'motion/react';
import { cn } from '@/lib/utils';
import { RefObject } from 'react';
export type ScrollProgressProps = {
className?: string;
springOptions?: SpringOptions;
containerRef?: RefObject<HTMLDivElement>;
};
const DEFAULT_SPRING_OPTIONS: SpringOptions = {
stiffness: 200,
damping: 50,
restDelta: 0.001,
};
export function ScrollProgress({
className,
springOptions,
containerRef,
}: ScrollProgressProps) {
const { scrollYProgress } = useScroll({
container: containerRef,
layoutEffect: Boolean(containerRef?.current),
});
const scaleX = useSpring(scrollYProgress, {
...DEFAULT_SPRING_OPTIONS,
...(springOptions ?? {}),
});
return (
<motion.div
className={cn('inset-x-0 top-0 h-1 origin-left', className)}
style={{
scaleX,
}}
/>
);
}