When click the dropdown hide it

This commit is contained in:
Yohan Boujon 2023-06-19 22:06:47 +02:00
parent a1284ca5a5
commit c5c3ebca24

View file

@ -8,6 +8,8 @@ var enterAnimation = false;
var dropdownList = document.getElementById("navbar_text-container").children[0].children; var dropdownList = document.getElementById("navbar_text-container").children[0].children;
//each <a> tag in the navbar //each <a> tag in the navbar
var aTagList = getNavbarTextContainer(); var aTagList = getNavbarTextContainer();
//a list
var dropdownStatus = Array(aTagList.length).fill(false);
/****************************************/ /****************************************/
/* animjs */ /* animjs */
@ -104,11 +106,18 @@ document.getElementById("navbar_logo-container").addEventListener("mouseleave",
for (var dropdownElement of dropdownList) { for (var dropdownElement of dropdownList) {
var dropdownLink = dropdownElement.children[0]; var dropdownLink = dropdownElement.children[0];
dropdownLink.addEventListener("click", function (e) { dropdownLink.addEventListener("click", function (e) {
if (e.target.parentNode.children.length > 1)
{
var styleDropdown = e.target.parentNode.children[1].style.display;
//We reset all navbar //We reset all navbar
resetNavbar(); resetNavbar();
//If the dropdown was hidden, show the item
if(!(styleDropdown == "block")) {
//we get the parent node of the <a> tag //we get the parent node of the <a> tag
var dropdownLink = e.target.parentNode; var dropdownLink = e.target.parentNode;
setDropdown("block", dropdownLink); setDropdown("block", dropdownLink);
}
}
}); });
} }