Copied!
It's on your clipboard.
You’ve been offline for 0 second. Please check your Internet connection.

Help Us Improve

Found an issue or have an idea? Let us know.
Select all that apply...
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Smart Sticky Header
Preview
Overview

This snippet lets you control your site’s header visibility for a smooth browsing experience. The header hides when scrolling down and reappears when scrolling up, with customizable thresholds. It can also auto-hide when the footer comes into view, keeping navigation accessible without taking up space.

Documentation
Code Setup
Walkthrough

Copy To Elementor
Step 1: Add Custom Script

Add this code with a snippets plugin right before the closing </body> tag.

Language
Copy
document.addEventListener('DOMContentLoaded', () => {
  const header = document.querySelector('[ou-header]');
  const footer = document.querySelector('[ou-footer]');
  if (!header) return;

  const HIDE_ON_SCROLL = true;   // hide on scroll down, show on scroll up
  const FOOTER_HIDES   = true;   // hide when footer enters viewport
  const THRESHOLD_PCT  = 5;      // % of page height before header can hide
  const REVEAL_UP_PCT  = 5;      // % of viewport height to scroll up before showing again

  let lastY = window.scrollY;
  let minScrollY = window.scrollY;
  let footerVisible = false;
  let headerHidden = false;

  const getThresholds = () => ({
    threshold: document.body.scrollHeight * (THRESHOLD_PCT / 100),
    revealUp: window.innerHeight * (REVEAL_UP_PCT / 100)
  });

  let { threshold, revealUp } = getThresholds();

  const toggleHeader = hide => {
    if (hide === headerHidden) return;
    headerHidden = hide;
    header.classList.toggle('is-hidden', hide);
  };

  const update = () => {
    const y = window.scrollY;
    const goingDown = y > lastY;

    if (!HIDE_ON_SCROLL) {
      if (FOOTER_HIDES && footerVisible) toggleHeader(true);
      else toggleHeader(false);
      lastY = y;
      return;
    }

    if (FOOTER_HIDES && footerVisible) {
      toggleHeader(true);
      lastY = y;
      return;
    }

    if (goingDown) {
      if (y > threshold) {
        toggleHeader(true);
        minScrollY = y;
      }
    } else {
      if (minScrollY - y > revealUp || y <= threshold) toggleHeader(false);
    }

    lastY = y;
  };

  if (footer) {
    const io = new IntersectionObserver(entries => {
      footerVisible = entries.some(e => e.isIntersecting);
      update();
    }, { threshold: 0.01 });
    io.observe(footer);
  }

  window.addEventListener('resize', () => {
    ({ threshold, revealUp } = getThresholds());
    update();
  }, { passive: true });

  window.addEventListener('scroll', update, { passive: true });
  update();
});
Step 2: Add Custom CSS

Add this code with a snippets plugin in <head>, or place it in Page CSS block or Site Settings. This CSS controls the fade-and-hide effect for the sticky header.

Language
Copy
[ou-header] {
  opacity: 1;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

[ou-header].is-hidden {
  opacity: 0;
  pointer-events: none;
}

Language
Copy

Language
Copy

Language
Copy

Language
Copy
Publish and preview live

Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.

Absolutely Codefree
If you were expecting some fancy snippet, sorry. This one runs just fine on its own.
C’mon, You Got This
Do we really need to spell this one out? It’s as straightforward as it gets.
Resorce Details
Collection
Basics
Category
Category
Interactions
Interaction
Builder
Last Updated
September 16, 2025