Skip to content
animorio
IT
All components

Hide-on-scroll top bar

Navigation, Scroll, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.1 KBGSAP 28 KBLenis 5.3 KBFreeDownload the zip

Scroll inside the preview

The top bar of Northwind Journal, a made-up magazine: at the top of the page it is transparent; as soon as the text moves under it, it takes a thin glass, a soft shadow and a 1 pixel edge that lights from left to right with a blue glint at its tip. Scrolling down it slides away with a little inertia, scrolling up even a little it drops back on a precise spring, and near the top it always stays.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Hide-on-scroll top bar" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Hide-on-scroll top bar</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- the top bar of a journal: transparent at the top of the page; once it lifts off the content it takes a thin
       glass, a soft shadow and a 1px edge that lights from left to right. Scrolling down it slides away with a little
       inertia, scrolling back up even a little it drops in on a tight spring. Focus inside it always brings it back. -->
  <header class="bar" data-bar>
    <div class="bar__glass" data-glass aria-hidden="true"></div>
    <div class="bar__edge" aria-hidden="true">
      <span class="bar__line" data-line></span>
      <span class="bar__glint" data-glint></span>
    </div>
    <div class="bar__inner" data-inner>
      <a class="brand" href="#" aria-label="Northwind Journal, home">
        <svg class="brand__mark" viewBox="0 0 24 24" aria-hidden="true">
          <rect x="2.5" y="2.5" width="19" height="19" rx="6"></rect>
          <path d="M8 16.2V8l8 8.2V8"></path>
        </svg>
        <span class="brand__name">Northwind<span class="brand__sub"> Journal</span></span>
      </a>

      <nav class="links" aria-label="Main">
        <a class="link is-active" href="#" aria-current="page"><span class="link__txt">Stories</span></a>
        <a class="link" href="#"><span class="link__txt">Essays</span></a>
        <a class="link link--wide" href="#"><span class="link__txt">Field notes</span></a>
        <a class="link link--wide" href="#"><span class="link__txt">About</span></a>
      </nav>

      <a class="cta" href="#" data-cta>
        <span class="cta__shine" aria-hidden="true"></span>
        <span class="cta__txt">Subscribe</span>
      </a>
    </div>
  </header>

  <main class="page" aria-hidden="true">
    <p class="hint" data-hint>
      <span>Scroll to read</span>
      <svg viewBox="0 0 12 12"><path d="M3 4.6 6 7.6l3-3"></path></svg>
    </p>
    <div class="col">
      <span class="ln ln--kicker"></span>
      <span class="ln ln--title" style="--w: 88%"></span>
      <span class="ln ln--title" style="--w: 62%"></span>
      <span class="ln ln--meta"></span>
      <div class="para"><span style="--w: 100%"></span><span style="--w: 96%"></span><span style="--w: 99%"></span><span style="--w: 72%"></span></div>
      <div class="para"><span style="--w: 98%"></span><span style="--w: 100%"></span><span style="--w: 94%"></span><span style="--w: 97%"></span><span style="--w: 44%"></span></div>
      <div class="fig"></div>
      <div class="para"><span style="--w: 100%"></span><span style="--w: 92%"></span><span style="--w: 97%"></span><span style="--w: 58%"></span></div>
      <span class="ln ln--head" style="--w: 46%"></span>
      <div class="para"><span style="--w: 99%"></span><span style="--w: 95%"></span><span style="--w: 100%"></span><span style="--w: 90%"></span><span style="--w: 66%"></span></div>
      <div class="para"><span style="--w: 97%"></span><span style="--w: 100%"></span><span style="--w: 52%"></span></div>
      <div class="fig fig--low"></div>
      <div class="para"><span style="--w: 100%"></span><span style="--w: 94%"></span><span style="--w: 98%"></span><span style="--w: 38%"></span></div>
      <div class="para"><span style="--w: 96%"></span><span style="--w: 100%"></span><span style="--w: 91%"></span><span style="--w: 70%"></span></div>
    </div>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/lenis@1.3.26/dist/lenis.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

24 values to change

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Hide-on-scroll top bar” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

At the top sits the bar of Northwind Journal, a made-up reading magazine: on the left the black symbol with the N and the name, then the links Stories (the active one, with a still grey fill), Essays, Field notes and About, on the right the black Subscribe button. Underneath scrolls an article made only of grey lines. At the top the bar is transparent; as soon as the page moves it takes the glass and the shadow, and its one pixel edge draws from left to right with a blue glint at the tip. Scrolling down more than 14 pixels in one go, the bar slides up and away, starting slowly as if it had a little weight; scrolling up even 6 pixels it drops back on a short spring, with a pixel of bounce, and its content follows a hair behind. Near the top it always stays, and back at the top the edge gathers away to the right and the glass fades. Over the links a soft fill blooms under the one you point at; the button has a shine that crosses it and squeezes a touch when pressed. If something in the bar takes the keyboard focus, the bar comes back.

How it works

A threshold, not the bare direction

Every frame the scroll is read and the pixels moved in the same direction add up: the bar hides only after HIDE_DELTA pixels down and comes back after SHOW_DELTA up, so a trackpad jitter never makes it jump. Above TOP_ZONE it always stays.

Two springs for two gestures

The position is a spring on GSAP's ticker, in two half steps per frame. Going away it is fully damped and soft (it starts slowly, the inertia); coming back it is stiffer and damped at 0.8, a pixel of bounce and no more.

The lip of glass

The bar starts 12 pixels above the page with as much glass on top: when the spring bounces down, what shows above is the bar itself, never a gap.

The edge that lights

Lifting off the content, a tween takes glass and shadow to 1 and draws the edge with scaleX from the left, a glint of the accent riding its tip; at the top the edge gathers away to the right.

Focus first

A focusin on the bar brings it down and keeps it there while the focus stays inside: keyboard users never land on an invisible link.

Values to change

NameFileDefaultWhat it changes
HIDE_DELTAscript.js14How many pixels you must scroll down in one go before the bar hides.
SHOW_DELTAscript.js6How many pixels you must scroll up in one go before the bar comes back.
TOP_ZONEscript.js96Above how many pixels from the top the bar never hides.
HIDE_STIFFNESSscript.js120The spring that slides the bar away: lower is a slower, softer start.
SHOW_STIFFNESSscript.js300The spring that drops the bar back in.
SHOW_DAMPINGscript.js0.8How much the drop-in spring is held back (1 = no overshoot).
EDGE_TIMEscript.js0.8How many seconds the 1 pixel edge takes to light from left to right.

Try them in the Playground

When to use it

For the header of a blog, a magazine, a docs site or a long landing page: where people read a lot and the bar should make room for the text going down, but be there as soon as you scroll back up looking for it.

On phones

The same threshold and springs with a finger: the bar is 56 pixels tall, Stories and Essays stay and the name drops «Journal»; under 360 pixels only the symbol stays next to the links.

With reduced motion

No sliding and no smooth scrolling: the bar fades out and back in in place, and the edge appears and goes without drawing.

Pitfalls

  • With the bare scroll direction the bar jumped at every trackpad jitter and at the autopilot's turn: now what counts is the pixels moved in a row, reset when the direction changes.
  • A drop-in spring with a real bounce uncovered a white gap above the bar: the bar starts 12 pixels higher with its own glass, and its position never goes past that lip.
  • The blue glint cannot live inside the line that grows with scaleX, or it gets squashed with it: it is a sibling, with its x in pixels measured again on resize.
  • Hidden, the bar kept its links reachable with Tab but out of sight: focusin brings it down and keeps it there while the focus stays inside.

Libraries

GSAP 3.15.0, Lenis 1.3.26, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 6.1 KB; the libraries: GSAP 28 KB, Lenis 5.3 KB.

Testing

Tested on 19 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components