Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing nav-bar color after scrolling?

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.

like image 528
user3641208 Avatar asked May 16 '14 23:05

user3641208


People also ask

How do I change the navbar color when I scroll in Reactjs?

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.

How can I change navbar color?

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.


1 Answers

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

like image 150
OzzyCzech Avatar answered Sep 21 '22 20:09

OzzyCzech