diff --git a/components/navbar.html b/components/navbar.html index ebc900b..c445045 100644 --- a/components/navbar.html +++ b/components/navbar.html @@ -1,6 +1,6 @@ - + - + diff --git a/css/base.css b/css/base.css index 460c004..4a19181 100644 --- a/css/base.css +++ b/css/base.css @@ -96,7 +96,7 @@ p { .loading-content img{ margin: 0.5rem; height: auto; - width: 30%; + max-width: 15rem; display: flex; margin-left: auto; margin-right: auto; diff --git a/js/navbar.js b/js/navbar.js index 80cf764..9678d09 100644 --- a/js/navbar.js +++ b/js/navbar.js @@ -8,6 +8,8 @@ var mobileMode = false var enterAnimation = false; //same but for menu var enterMenuAnimation = false; +//when menu is opened or not +var menuOpened = false; //each tag of the navbar_text-container var dropdownList = document.getElementById("navbar_text-container").children[1].children; //each tag in the navbar @@ -55,6 +57,16 @@ var menuAnimation = anime({ autoplay: false, }); +var navbarAnimation = anime({ + targets: '#navbar_text-container', + translateX: [ + { value: "", duration: 0, delay: 0 }, + { value: "-20rem", duration: 300, delay: 0 } + ], + easing: 'easeOutExpo', + autoplay: false +}) + /****************************************/ /* functions */ /****************************************/ @@ -94,12 +106,30 @@ function resetNavbar() { } } -function openMenu() { - document.getElementById("navbar_text-container").style.display = "block"; +function openMenu(playAnimation) { + menuOpened=true; + if (playAnimation) { + document.getElementById("navbar_text-container").style.display = "block"; + navbarAnimation.reverse(); + navbarAnimation.restart(); + } + else { + document.getElementById("navbar_text-container").style.display = "block"; + } } -function closeMenu() { - document.getElementById("navbar_text-container").style.display = "none"; +function closeMenu(playAnimation) { + menuOpened=false; + if (playAnimation) { + navbarAnimation.reverse(); + navbarAnimation.restart(); + navbarAnimation.finished.then(() => { + document.getElementById("navbar_text-container").style.display = "none"; + }) + } + else { + document.getElementById("navbar_text-container").style.display = "none"; + } } /****************************************/ @@ -195,14 +225,20 @@ window.addEventListener('click', function (e) { //When changing the window size window.addEventListener('resize', function (e) { - if((window.innerWidth > 800) && mobileMode) - { - openMenu(); + if ((window.innerWidth > 800) && mobileMode) { + //when switching from mobile to computer + document.getElementById("navbar_text-container").style.transform = ""; + openMenu(false); + if(menuOpened) + { + navbarAnimation.reverse(); + } mobileMode = false; } - if((window.innerWidth < 800) && !mobileMode) - { - closeMenu(); + if ((window.innerWidth < 800) && !mobileMode) { + //when switching from computer to mobile + console.log("computer to mobile"); + closeMenu(false); mobileMode = true; } });