I have fixed bootstrap menu on the top of the page and an asbolutely positioned scroll button .btn-navigate at the bottom of the viewport (in #home-slide). On (any) scroll, I want the fixed menu to change background from transparent to semigray and also the scroll button to disappear. The button should keep on being hidden from now on, but when I scroll to the top, I need the menu to become transparent again.
For this purpose I am using jQuery Waypoints. I have achieved both effects using the following code, but when I scroll, the menu jumps, EDIT: More specificaly it flashes as if the menu is not at fixed position all the time. When I scroll, it sometimes look as if the menu scroll out with the page and then suddenly jumps back in the fixed position. Sometimes after a while is starts to work correctly. It s not jumping if I remove the following two lines of code, but I need the same trigger for both events.
EDIT2: It is also not flashing if I don't use waypoints with the menu. The scrolling is smooth and the menu is always atop of all other elements in the page.
$("#home-slide .btn-navigate").removeClass("pulse animated");
$("#home-slide .btn-navigate").addClass("fadeOutUp animated2");
HTML:
<header id="masthead">
<nav class="navbar navbar-fixed-top">
<div class="container">
MENU CONTENT
</div>
</nav>
</header>
<section id="home-slide">
<div class="container">
<h1 class="heading">HEADING</h1>
<p class="font2">
TEXT</p>
<a href="#" class="btn-navigate animated pulse">Scroll Button</a>
</div>
</section>
jQuery:
jQuery(document).ready(function ($) {
$(function () {
$("#masthead nav").waypoint(function () {
$("#masthead nav").toggleClass('scrolling');
$("#home-slide .btn-navigate").removeClass("pulse animated");
$("#home-slide .btn-navigate").addClass("fadeOutUp animated2");
}, { offset: '-20px' });
});
});
MY Navigation CSS:
#masthead {
nav {
min-height: 120px;
padding-top: 2.727rem;
background: rgba(51,58,64,0.0);
-webkit-transition: background-color 0.5s linear;
.container {
position: relative;
}
.navbar-nav {
a {
color: @lms-white;
font-weight: bold;
text-transform: none;
text-shadow: 1px 1px 2px rgba(50, 50, 50, 1);
padding: 7px 1.17rem;
border: 2px solid transparent;
.border-radius(5px);
&:hover {
background: transparent;
border: 2px solid @lms-pink;
}
}
}
.navbar-brand {
padding: 7px 15px;
}
&.scrolling {
background: rgba(51,58,64,0.9);
-webkit-transition: background-color 0.5s linear;
}
}
Bootstrap Navigation CSS:
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-fixed-top, .navbar-fixed-bottom {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
}
.navbar {
position: relative;
min-height: 50px;
margin-bottom: 20px;
border: 1px solid transparent;
}
Any idea how to solve this? Thank you!
I have found the solution. The blinking was not cause by Waypoints. Adding
-webkit-backface-visibility: hidden; /* Chrome, Safari, Opera */
backface-visibility: hidden;
to nav solved the problem.