Created
January 5, 2020 20:11
-
-
Save Agressiva86/7fa3f372b85181ec200d1c6fa80d4fdb to your computer and use it in GitHub Desktop.
Add background for header with dropdown menu and scrollTop // JM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window).scroll(function() { | |
if($(window).scrollTop() === 0) { | |
$("#header").removeClass("background"); | |
} else { | |
$("#header").addClass("background"); | |
} | |
}); | |
$(".main-navigation .has-submenu a").click(function() { | |
$(this).toggleClass("is-active"); | |
$(".header-drop-down").toggleClass("show-header-drop-down"); | |
if($(window).scrollTop() === 0) { | |
$("#header").toggleClass("background"); | |
} else { | |
$("#header").addClass("background"); | |
} | |
return false; | |
}); | |
if($(window).scrollTop() === 0) { | |
$("#header").removeClass("background"); | |
} else { | |
$("#header").addClass("background"); | |
} | |
$('body').click(function(event) { | |
if (!$(event.target).closest(".show-header-drop-down").length) { | |
$(".main-navigation .has-submenu a").removeClass("is-active"); | |
$(".header-drop-down").removeClass("show-header-drop-down"); | |
if($(window).scrollTop() === 0) { | |
$("#header").removeClass("background"); | |
} | |
} | |
}) | |
$(".header-drop-down li a").click(function() { | |
$(".header-drop-down").removeClass("show-header-drop-down"); | |
$("html, body").removeClass("overflowhidden"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment