This snippet creates a header that becomes fixed and slides down after the page has been scrolled.
- The header behaves normally at the top of the page.
- After scrolling past a defined distance, it becomes fixed.
- It slides down from the top and remains visible while scrolling.
- The header automatically accounts for the WordPress admin bar when logged in.
Update the selector so it targets your header element.
Current selector:
.bde-header-builder-89-121This number will be different on other sites.
Look at your header markup. For example:
<header class="bde-header-builder-123-456 ...">Then update all selectors in both the JS and CSS to match:
.bde-header-builder-123-456Make sure you update every occurrence.
In the JavaScript you will see:
window.scrollY > 100Change 100 to adjust when the header becomes sticky.
Examples:
Header appears sooner:
window.scrollY > 50Header appears later:
window.scrollY > 200In the CSS file you will see:
background-color: purple;Change this to match your design.
Example:
background-color: #ffffff;If the header appears behind other elements, increase:
z-index: 999999;In most cases this will not need to change.
No changes are required.
The header automatically offsets itself using the WordPress variable:
--wp-admin--admin-bar--heightThis ensures the header sits correctly below the admin bar when logged in.
As a minimum, you need to update:
- The header selector (
.bde-header-builder-XX-XXX) - The scroll trigger value (
100) - The background colour