Search

Back

Copy Link

Library

/

Free

/

61

Hide Header on Scroll

61

Hide Header on Scroll

Not loading? Preview

Made by

@frameroverrides

override

scroll

Override

Hide Header on Scroll

Copy

Override

Copied to Clipboard!

Instructions

Apply this effect to a regular frame or stack around your header component, not the component itself.

Change the line 7 movement amount to the height of your header. Your header container should be set to sticky as well.

To apply to a bottom bar, change the movement amount from negative to positive

Code Preview

import type { ComponentType } from "react"
import { useRef, useEffect } from "react"
import { motion, useSpring } from "framer-motion"

export function withScrollEffect(
    Component,
    movementAmount = -80 // Set the height of your navigation here
): ComponentType {
    return (props) => {
        const y = useSpring(0, { stiffness: 120, damping: 30 })
        const lastScrollY = useRef(0)

        useEffect(() => {
            const handleScroll = () => {
                const scrollDirection =
                    window.scrollY > lastScrollY.current ? "down" : "up"
                lastScrollY.current = window.scrollY
                if (scrollDirection === "down") {
                    y.set(movementAmount)
                } else {
                    y.set(0)
                }
            }

            window.addEventListener("scroll", handleScroll)

            return () => {
                window.removeEventListener("scroll", handleScroll)
            }
        }, [])

        return <Component {...props} as={motion.div} style={{ y }} />
    }
}

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.