To create a navbar that hides on scroll down and shows on scroll up in Webflow, you need to use Webflow’s Interactions panel combined with a small amount of custom code to detect scroll direction.
.navbar
) for targeting with interactions and code.Webflow’s built-in scroll triggers don’t include scroll direction detection, so you’ll need to handle this with custom code.
But you still need animations prepared:
Inside your project, go to Page Settings, scroll to the Before
tag custom code section, and add:
let lastScrollTop = 0;const navbar = document.querySelector('.navbar');window.addEventListener('scroll', function() { let scrollTop = window.pageYOffset || document.documentElement.scrollTop; if (scrollTop > lastScrollTop) { // scrolling down navbar.setAttribute('data-scroll', 'down'); Webflow.require('ix2').actions.trigger({ id: 'HIDE_NAVBAR_ANIMATION_ID', group: 'HIDE_NAVBAR_ANIMATION_NAME' }); } else { // scrolling up navbar.setAttribute('data-scroll', 'up'); Webflow.require('ix2').actions.trigger({ id: 'SHOW_NAVBAR_ANIMATION_ID', group: 'SHOW_NAVBAR_ANIMATION_NAME' }); } lastScrollTop = scrollTop <= 0 ? 0 : scrollTop; // For mobile or negative scrolling});
Note: Replace HIDE_NAVBAR_ANIMATION_ID
and SHOW_NAVBAR_ANIMATION_ID
with the actual IDs of your animations. Webflow doesn't expose these directly, so a simpler and more reliable method is explained below.
An easier way is:
hide
and show
, and use combo-class-based animations in Webflow.In the Before </body>
section:
let lastScrollTop = 0;const navbar = document.querySelector('.navbar');window.addEventListener('scroll', function() { let scrollTop = window.pageYOffset || document.documentElement.scrollTop; if (scrollTop > lastScrollTop) { navbar.classList.add('nav-hidden'); navbar.classList.remove('nav-visible'); } else { navbar.classList.add('nav-visible'); navbar.classList.remove('nav-hidden'); } lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;});
Then in Webflow:
.nav-hidden
and one for .nav-visible
.To create a scroll-aware mobile navbar in Webflow:
This method offers smooth UX especially useful for content-heavy, mobile-first designs.