I'm trying to add CSS to my navbar so that when the user scrolls down the navbar background will slide from the top. Right now the background is just appearing with no transition. What am I missing?
Here's what I have written for jQuery:
$(function () {
$(document).scroll(function () {
const $nav = $(".navbar");
$nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
});
});
SCSS:
.navbar {
position: fixed;
z-index: 1;
width: 100%;
&.scrolled {
background-color: #FDFDFD;
transition: background-color top 1s;
padding-bottom: 24px;
width: 100%;
}
}
HTML:
<div class="navbar">
<navbar class="grid-1">
<img class="navbar-logo" src="#" alt="Website">
<a class="navbar-links-li-1" href="#">Workshops</a>
<a class="navbar-links-li-2" href="#">Resources</a>
<a class="navbar-links-li-3" href="#">Donate</a>
</navbar>
</div>
<section class="main grid-1">
<p>blah</p>
</section>