Reputation: 646
I want to achieve 2 things when in responsive small screen size:
I'm now using svg images for the nav-btn.
I know that i have to add a removeClass action on the scroll event, but tried some different things, but my JS-skills aren't that good.
Hope there is someone that can help or guide me threw this either the one or the other.
Screenshots:
Cross need to changes back in hamburger icon on scroll:
Html:
<header>
<nav>
<div class="col-nav">
<a href="#" class="nav-btn"></a>
<a href="#" class="home">Logo</a>
</div>
<ul>
<li class="col-nav"><a href="#">Item1</a></li>
<li class="col-nav"><a href="#">Item2</a></li>
<li class="col-nav"><a href="#">Item3</a></li>
</ul>
</nav>
</header>
Javascript:
$(function() {
$('.nav-btn').click(function() {
$('nav ul').fadeToggle(300);
$(this).toggleClass("open");
})
});
$(window).scroll(function() {
if ($(this).scrollTop() > 50) {
$('nav ul').hide(); }
});
Upvotes: 0
Views: 626
Reputation: 2108
Add $('.nav-btn').removeClass('open');
$(window).scroll(function() {
if ($(this).scrollTop() > 50) {
$('nav ul').hide();
$('.nav-btn').removeClass('open');
}
});
Upvotes: 1