I need my sticky Navbar text to be white when it’s on the top of my page, but when I scroll down few px I need the text to change to black (that’s because I use transparent header background)
I’m willing to create something like the navbar behavior at this site https://www.rolex.com
I use WordPress Elementor.
I’ve managed to make my navbar disappear when scrolling down and popup when scrolling up.
and to be transparent on the top of the page and white background otherwise.
3
Answers
Since you are using WordPress – you might want to use jQuery for changing the color of your text in the navbar.
Here is the code example which makes your elements
<a>
and<p>
turn black when you scroll down and pass 10px threshold and it’s back to white when you are at the top of the page (accurately – less than 10px to the top, but you can change the breakpoint in the code to your needs).With the given HTML code:
You apply the following JavaScript code:
where you listen to “scroll” event and change the color based on the relative position of your header to the top of the page.
P.S. If you use EcmaScript 5 version feel free to change
const
tovar
. But in general, you should be fine.If I understood right, you wanted something like this (I didn’t use anything other than pure HTML, CSS and JS) :
You mean something like this?
Because you didn’t add your code in the answer, I can’t specifically your code, but maybe my code will help you to adapt your code with my example.
The navbar color you can change if you want