Webflow sync, pageviews & more.
NEW

How can I implement a navbar that shows on scroll-up and hides on scroll-down in Webflow? This feature is particularly useful for mobile browsing.

TL;DR
  • Give your fixed-position navbar a unique class and add the attribute data-scroll="navbar".
  • Add JavaScript in the Footer Code section to detect scroll direction and toggle the navbar's transform style to hide on scroll-down and show on scroll-up.
  • Optionally, enhance smoothness with CSS transitions or Webflow interactions.

To create a navbar that hides on scroll-down and shows on scroll-up in Webflow, you'll need to use custom JavaScript in combination with Webflow’s native interactions system for visibility settings.

1. Add Your Navbar to the Page

  • Use Webflow’s Navbar component or create your own using a Div Block.
  • Ensure the navbar has a fixed position (top) so it stays at the top of the screen.

2. Assign an ID or Class to the Navbar

  • Select the Navbar element.
  • Under the Selector, give it a class name like scroll-navbar.

3. Add Custom Attributes for JavaScript Control

  • Go to the Element Settings panel for the navbar.
  • Add an attribute:
  • Name: data-scroll
  • Value: navbar

4. Add Custom JavaScript for Scroll Detection

  • Go to Page Settings > Custom Code > Footer Code.
  • Paste this script just before the </body> tag:
<script>let lastScrollTop = 0;const navbar = document.querySelector('[data-scroll="navbar"]');window.addEventListener("scroll", function() {  const scrollTop = window.pageYOffset || document.documentElement.scrollTop;    if (scrollTop > lastScrollTop) {    // Scrolling down    navbar.style.transform = "translateY(-100%)";    navbar.style.transition = "transform 0.3s ease";  } else {    // Scrolling up    navbar.style.transform = "translateY(0)";    navbar.style.transition = "transform 0.3s ease";  }    lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;}, false);</script>
  • This script checks the scroll direction and moves the navbar out of view on scroll-down, and back into view on scroll-up.

5. Optional: Add Smoother Behavior Using CSS

  • In the Navbar element’s style panel, under the Transforms section:
  • Set the Initial State of Move Y to 0px.
  • You can also use Webflow Interactions to control the same effect if you prefer no code, but JavaScript is more efficient for scroll detection.

6. Publish and Test Responsiveness

  • Publish your site and test on mobile devices to confirm the navbar hides on scroll-down and appears on scroll-up.

Summary

To implement a responsive scroll-up show / scroll-down hide navbar, use custom JavaScript to detect scroll direction and apply transform styles to the navbar using a unique selector. Combine this with a fixed navbar and transitions to ensure smooth animations.

Rate this answer

Other Webflow Questions