Staaarter

Sticky Scroll Shadow

A navbar pinned to the top of the viewport with `sticky top-0` that stays borderless and flat at the top of the page, then picks up a visible shadow and border the moment the page scrolls past a small threshold, a common way to give a sticky header some depth once content is passing underneath it.

By Staaarter Team
Navbar
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/sticky-scroll-shadow.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/navbar/navbar14.tsx instead.

Usage

The file also exports navbar14Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Navbar14, navbar14Demo } from "@/components/blocks/navbar/navbar14";

export default function Page() {
  return <Navbar14 {...navbar14Demo} />;
}

Props

PropTypeDefaultDescription
wordmarkstring"Solace"Logo text rendered as a bold wordmark.
links{ label: string; href: string }[]nonePrimary nav links, shown on medium screens and up.
cta{ label: string; href: string }noneThe single call-to-action button on the right.
classNamestringnoneExtra classes for the outer header element.

Behavior notes

  • Real client-side behavior: a useEffect attaches a genuine `scroll` event listener and flips a useState boolean once the page has scrolled more than 10px, which swaps in a shadow and a solid border class.
  • The scroll listener is attached to `headerRef.current.ownerDocument.defaultView`, not the bare `window` global, this repo's block detail pages render the live preview inside a portaled iframe, and listening on the bare `window` would attach to the wrong (parent) window and never fire for scrolling inside the iframe.
  • The listener is removed in the effect's cleanup function on unmount, and it also runs once immediately on mount to set the correct initial state.
  • The header itself uses `sticky top-0 z-10` positioning so it stays pinned while the rest of the page scrolls underneath it.