I have a very simple navbar that changes on scroll. The logo is supposed to be prepended and it does but every time the page is scrolled it adds another logo. I have a boolean in there to check whether the logo has been added but it still runs the code anyway. Here is my code:
$(window).scroll(function() {
var scroll = $(window).scrollTop(),
hidden = true;
if (scroll >= 470) {
$('#nav').addClass('static-nav');
if(hidden) {
$('#logo').prepend(' <div class="logo-container"> <img src="img/logo3.png" alt="logo"></div>');
hidden= false;
}
}else{
$('#nav').removeClass('static-nav');
if(!hidden) {
$('.logo-container').remove();
hidden = true;
}
}
});