Hi There,
Hope everyone is well!
I was wondering if anyone knows how to make a sticky announcement bar?
Theme: Palo Alto
Website URL: https://www.theluxelab.com.au/
Any help would be greatly appreciated.
Thank you in advance!
Hi There,
Hope everyone is well!
I was wondering if anyone knows how to make a sticky announcement bar?
Theme: Palo Alto
Website URL: https://www.theluxelab.com.au/
Any help would be greatly appreciated.
Thank you in advance!
Hi @MollieHammond ,
.announcement-bar-sticky {
position: sticky !important;
top: 60px;
z-index: 135;
}
Save and close theme.css
Open theme.js and paste the following at the bottom;
// When the user scrolls the page, execute stickyFunction
window.onscroll = function() {stickyFunction()};
// Get the navbar
const navbar = document.getElementById("NavStandard");
//Get the announcement bar
const announcementBar = document.querySelector(".announcement-bar-static");
// Get the offset position of the navbar
const sticky = navbar.offsetTop;
// Add the sticky class to the announcement bar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function stickyFunction() {
if (window.pageYOffset >= sticky) {
announcementBar.classList.add("announcement-bar-sticky")
} else {
announcementBar.classList.remove("announcement-bar-sticky");
}
}
Save and close the file.
Refresh to test the feature.
if this worked for you, please mark as solution.
That worked perfectly! You’re an absolute legend, thanks so much!