How can I set the navbar with no background color?
When scrolling down after a div the nav-bar gets a new background-color (the nav-bar should be fixed at top, I use navbar-fixed-top
in Bootstrap)
I've tried some tutorials but I didn't succeed.
This is the website : http://attafothman.olympe.in/
I'm talking about that black nav-bar on top.
To create the rendering of the background color change of the navbar you will have to create a useEffect where you will pass the changeBackground function and an event listener that will be on scroll and passing the changeBackground function, like so.
The text color of the navigation bar can be changed using two inbuilt classes: navbar-light: This class will set the color of the text to dark. This is used when using a light background color. navbar-dark: This class will set the color of the text to light.
Here is simplest way how to change navbar color after window scroll:
Add follow JS to head:
$(function () { $(document).scroll(function () { var $nav = $(".navbar-fixed-top"); $nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height()); }); });
and this CSS code
.navbar-fixed-top.scrolled { background-color: #fff !important; transition: background-color 200ms linear; }
Background color of fixed navbar will be change to white when scroll exceeds height of navbar.
See follow JsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With