Search

Back

Copy Link

Library

/

Free

/

45

Scroll Progress Bar

45

Scroll Progress Bar

Not loading? Preview

Made by

@frameroverrides

override

scroll

Override

Scroll Progress Bar

Copy

Override

Copied to Clipboard!

Instructions

Set the frame that you want to act as your progress to "fill" it's container. If you want to round the edges with radius, place inside of a stack and set overflow to hidden then add radius to the stack.

Code Preview

import type { ComponentType } from "react"
import { useViewportScroll, useTransform, useAnimation } from "framer-motion"
import { useEffect, useState } from "react"

export function withScrollProgress(Component): ComponentType {
    return (props) => {
        const { scrollY } = useViewportScroll()
        const [scrollRange, setScrollRange] = useState([0, 0])
        const x = useTransform(scrollY, scrollRange, [0, 0])
        const scaleX = useTransform(scrollY, scrollRange, [0, 1])

        useEffect(() => {
            const scrollHeight =
                document.documentElement.scrollHeight - window.innerHeight
            setScrollRange([0, scrollHeight])
        }, [])

        return (
            <Component
                {...props}
                style={{
                    x,
                    scaleX,
                    originX: 0,
                }}
            />
        )
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.