From 4ec7817decdf9b119d84f5592bb894567a4e7c50 Mon Sep 17 00:00:00 2001 From: suroh Date: Sun, 8 Mar 2020 12:58:53 +0100 Subject: [PATCH] fixed primary nav toggle --- assets/css/master.css | 7 +++++-- assets/js/interaction.js | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/assets/css/master.css b/assets/css/master.css index cd4e0ea..a8f4d7e 100644 --- a/assets/css/master.css +++ b/assets/css/master.css @@ -107,12 +107,15 @@ nav#sub.active { nav#sub > ul { padding: 0px; margin: 0px; - height: 0px; + max-height: 0px; overflow: hidden; + opacity: 0; + transition: opacity 0.5s ease, max-height 0.025s ease; } nav#sub > ul.active { - height: inherit; + max-height: 50vh; + opacity: 1; } nav#toTop { diff --git a/assets/js/interaction.js b/assets/js/interaction.js index 3cbaefb..3e71298 100644 --- a/assets/js/interaction.js +++ b/assets/js/interaction.js @@ -37,6 +37,17 @@ let menuItem = document.querySelector('#menuItem') let menuVoices = [] +// check if any primaryNav items are active +const primaryActive = () => { + let active = false + for (let n of primaryNav) { + if (n.classList.contains('active')) { + active = true + } + } + return active +} + for (let n of primaryNav) { // remove shitty firefox span spacing n.nextSibling.parentNode.removeChild(n.nextSibling) @@ -58,12 +69,14 @@ for (let n of primaryNav) { } // subnav is nav element - if (!subNav.classList.contains('active')) { + if (primaryActive()) { subNav.classList.add('active') + } else { + subNav.classList.remove('active') } for (let s of subNav.children) { - if (s.id == n.dataset.link) { + if (s.id == n.dataset.link && primaryActive()) { s.classList.add('active') } else { s.classList.remove('active')