My navbar has a white background, but it should be transparent on the landing page and white when i scroll down and white on every other page.
I used the code from: Changing nav-bar color after scrolling?
EDIT:
So I added a fiddle with the answer below but somehow its not working
https://jsfiddle.net/jy6njukm/
Here's my code:
javascript:
$(document).ready(function(){
var scroll_start = 0;
var change_color = $('#change_color');
var offset = change_color.offset();
if (change_color.length){
$(document).scroll(function() {
scroll_start = $(this).scrollTop();
if(scroll_start > offset.top) {
// the white normal navbar
$(".navbar-add").removeClass("navbar-trans");
} else {
// what the users sees when he lands on the page
$(".navbar-add").addClass("navbar-trans");
}
});
}
});
Here is my navbar css:
.navbar-fixed {
position: fixed;
height: 70px;
padding: 0px 30px;
left: 0px;
top: 0px;
z-index: 50;
width: 100%;
background-color: white;
box-shadow: 0 1px 5px 0 rgba(0,0,0,0.07),0 1px 0 0 rgba(0,0,0,0.03);
}
.navbar-trans {
background-color: transparent !important;
box-shadow: none !important;
}
And I have my navbar html with only
<div class="navbar-fixed navbar-add">
.....
</div>
and my home.html.erb with
<div class="container-fluid banner bg-picture" id="change_color"
style="background-image: linear-gradient(-225deg, rgba(0,0,0,0.2) 0%,
rgba(0,0,0,0.35) 50%), url('<%= asset_path('banner_logo.jpeg') %>')">
</div>
It kind of works but the problem now is, that everytime I refresh the page, the navbar is still white and it only turns transparent when I scroll up, to the top of the page. It turns white when I scroll down though, like I want it to be.
I inspected the page and everytime I refresh it, the background-color of the class is still white even though I set this to be transparent in the javascript?
How can I make it possible that the background-color of my navbar is transparent on my landing page?