Navbar fully functionnal with dropdown. Added getNavbarTextContainer(), resetNavbar() functions and dropdownList, aTagList variables
This commit is contained in:
parent
d072c19c8f
commit
da3809cd35
1 changed files with 68 additions and 10 deletions
72
js/navbar.js
72
js/navbar.js
|
@ -1,4 +1,14 @@
|
|||
var enterAnimation;
|
||||
/****************************************/
|
||||
/* global variables */
|
||||
/****************************************/
|
||||
|
||||
var enterAnimation = false;
|
||||
var dropdownList = document.getElementById("navbar_text-container").children[0].children;
|
||||
var aTagList = getNavbarTextContainer();
|
||||
|
||||
/****************************************/
|
||||
/* animjs */
|
||||
/****************************************/
|
||||
|
||||
var logoRotate = anime({
|
||||
targets: '.navbar_logo',
|
||||
|
@ -8,18 +18,45 @@ var logoRotate = anime({
|
|||
autoplay: false,
|
||||
direction: 'normal',
|
||||
update: function (anim) {
|
||||
console.log(anim.progress+" : enter ? "+enterAnimation);
|
||||
if(anim.progress >= 10 && enterAnimation)
|
||||
{
|
||||
//console.log(anim.progress+" : enter ? "+enterAnimation);
|
||||
if (anim.progress >= 10 && enterAnimation) {
|
||||
document.getElementsByClassName("navbar_logo")[0].style.filter = "brightness(50%)";
|
||||
}
|
||||
if(anim.progress <= 10 && !enterAnimation)
|
||||
{
|
||||
if (anim.progress <= 10 && !enterAnimation) {
|
||||
document.getElementsByClassName("navbar_logo")[0].style.filter = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/****************************************/
|
||||
/* functions */
|
||||
/****************************************/
|
||||
|
||||
function setDropdown(display, element) {
|
||||
if (element.children.length > 1) {
|
||||
element.children[1].style.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
function getNavbarTextContainer() {
|
||||
var returnAtag = [];
|
||||
var container = document.getElementById("navbar_text-container");
|
||||
for (var aTag of container.children[0].children) {
|
||||
returnAtag.push(aTag.children[0])
|
||||
}
|
||||
return returnAtag;
|
||||
}
|
||||
|
||||
function resetNavbar() {
|
||||
for (dropdownClass of document.getElementsByClassName("navbar_dropdown")) {
|
||||
dropdownClass.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
/* main */
|
||||
/****************************************/
|
||||
|
||||
document.getElementById("navbar_logo-container").addEventListener("mouseenter", function () {
|
||||
enterAnimation = true;
|
||||
logoRotate.play();
|
||||
|
@ -29,7 +66,6 @@ document.getElementById("navbar_logo-container").addEventListener("mouseenter",
|
|||
});
|
||||
|
||||
document.getElementById("navbar_logo-container").addEventListener("mouseleave", function () {
|
||||
console.log("leave")
|
||||
enterAnimation = false;
|
||||
logoRotate.reverse();
|
||||
logoRotate.play();
|
||||
|
@ -38,3 +74,25 @@ document.getElementById("navbar_logo-container").addEventListener("mouseleave",
|
|||
enterAnimation = true;
|
||||
})
|
||||
});
|
||||
|
||||
for (var dropdownElement of dropdownList) {
|
||||
var dropdownLink = dropdownElement.children[0];
|
||||
dropdownLink.addEventListener("click", function (e) {
|
||||
var dropdownLink = e.target.parentNode;
|
||||
resetNavbar();
|
||||
setDropdown("block", dropdownLink);
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('click', function (e) {
|
||||
var clickState = false;
|
||||
for (dropdownClass of document.getElementsByClassName("navbar_dropdown")) {
|
||||
clickState |= dropdownClass.contains(e.target);
|
||||
}
|
||||
for (aTag of aTagList) {
|
||||
clickState |= aTag.contains(e.target);
|
||||
}
|
||||
if (!clickState) {
|
||||
resetNavbar();
|
||||
}
|
||||
});
|
Loading…
Add table
Reference in a new issue