Skip to example

Scroll Direction: Hide Header

A sticky header that hides when scrolling down and reappears when scrolling up. Uses useMotionValueEvent to detect scroll direction.

React

Source code

"use client"

import { motion, useScroll, useMotionValueEvent } from "motion/react"
import { useState } from "react"

export default function ScrollHideHeader() {
    const { scrollY } = useScroll()
    const [hidden,