- This topic has 11 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
March 12, 2023 at 10:40 pm #2565443
David
Hi Everyone,
I actually asked this question a while back, and got it working, but that site changed, so I can’t reference back to it now to look at the CSS used.
And I suspect something has changed over time anyway.The link below is where I am testing a copy of a live site.
I need the new top bar I created (wtih the two buttons) to be sticky when you scroll down, so both the top bar and sticky header/menu are on top of each other.The height of the top bar is 46 px
I found 6 or 7 simialr articles but none seemed to work for me…
TIA, DaveMarch 12, 2023 at 11:06 pm #2565456Fernando Customer Support
Hi David,
Hook your 2 buttons to
above_headerinstead. Then add this CSS:nav#sticky-navigation.is_stuck { top: 45.5px !important; } .gb-container.gb-container-26cec0c6.top-bar { position: sticky; top: 0; }March 12, 2023 at 11:23 pm #2565472David
Thanks Fernando,
I’m not seeing a above_header ?
Do I add that in custon ?
DaveMarch 12, 2023 at 11:41 pm #2565481Fernando Customer Support
How did you add the Top bar exactly?
March 13, 2023 at 12:02 am #2565492David
Oh, its an element, that is a block, with hook with before header. Priority 10, and entire site
DaveMarch 13, 2023 at 12:11 am #2565499Fernando Customer Support
Can you give it a priority of 1 instead?
March 13, 2023 at 12:50 am #2565535David
OK, thanks its moving forward.
Now the background color is tranparent.
I’ve tried to set the background color, but it is not sticking.Is it possible to have it transparenet before sticky, but fixed color when you scroll down and the top-bar and header come in ?
TIA, Dave
March 13, 2023 at 1:20 am #2565571Fernando Customer Support
Can you try adding this CSS?:
.gb-container.gb-container-26cec0c6.top-bar { position: fixed; left: 50%; transform:translateX(-50%); background:transparent; z-index: 100; } .header-wrap { top: 50.6px; }March 13, 2023 at 2:09 am #2565635David
Thanks,
I took out the left: 50% and the tranform:translate, that seemed to mess up the top bar position of the buttons.
So the top bar is good!
Just need the sticky menu to have a fixed colour – which I think I have working.
I added the top entry below, and the rest is a mix of yours modified and mine!
Thanks for your patience !.sticky-enabled .main-navigation.is_stuck { background-color: #eceff1; } .gb-container.gb-container-26cec0c6.top-bar { position: fixed; background:transparent; z-index: 100; } .header-wrap { top: 50.6px; } nav#sticky-navigation.is_stuck { top: 50.6px !important; } .gb-container.gb-container-26cec0c6.top-bar { position: sticky; top: 0; background-color: #eceff1; }Dave
March 13, 2023 at 5:27 am #2565833David
StaffCustomer SupportHi Dave,
is it all working as you need it to ?
March 13, 2023 at 6:16 am #2565912David
Hi David,
It’s pretty close – the sticky functionality is all OK.
I would idealy like the top-bar to be transparent, before being sticky, then it switches to a solid color.
TIA, Dave
ps late here, so may not be able to reply until the morningMarch 13, 2023 at 11:26 am #2566380David
StaffCustomer SupportIt would need some Javascript:
<script> // Get the topBar const topBar = document.querySelector('.top-bar'); // create a debounce for performance function debounce(func, delay) { let timer; return function() { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, arguments); }, delay); } } // add is_stuck clas to topBar if the window is not top function addClassIfNotTop() { if (window.scrollY > 0) { topBar.classList.add('is_stuck'); } else { topBar.classList.remove('is_stuck'); } } window.addEventListener('scroll', debounce(addClassIfNotTop, 100)); // Add a scroll event listener to the window using the debounced function window.addEventListener('scroll', debounce(addClassIfNotTop, 100)); </script>Hook that into the
wp_footerof the pages its required.On scroll it will add the
is_stuckclass to yourtop-barblock element.So you can use some CSS to make the background transparent when its not stuck:
.top-bar:not(.is_stuck) { background: transparent !important; }Might need some negative margins to bring the content up behind the top bar…
-
AuthorPosts
- You must be logged in to reply to this topic.