I am trying to achieve a scroll effect on my page where the header will move up when scrolling up, but at position 150 it should smoothly slide down and stay fixed at the top. I have tried various methods but haven't been able to get it right. Can someone take a look at my code?
Something similar to this , although this script has some issues.
jQuery(document).ready(function ($) {
$(window).scroll(function () {
if ($(window).scrollTop() >= 100) {
$('.navarea').addClass('fixed-header');
} else {
$('.navarea').removeClass('fixed-header');
}
});
});
Here is the CSS:
.navarea {
z-index: 2;
background: rgba(255, 255, 255, 0.9);
transition: all 0.5s ease-in-out;
}
.fixed-header {
position: fixed;
background: rgba(255, 255, 255, 0.9);
text-shadow: none;
padding-bottom: 0;
top: 0;
z-index: 5;
transition: all 0.5s ease-in-out;
}
View live demo here: https://codepen.io/pagol/pen/XovvGJ