From 95a0fc5064a770b9f2baf14852bbbd4bfa065990 Mon Sep 17 00:00:00 2001 From: Andrew Simonson Date: Mon, 23 May 2022 18:06:32 -0400 Subject: [PATCH] minimize and scroll on navigation --- src/responsive.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/responsive.js b/src/responsive.js index c8ed965..10f6fd6 100644 --- a/src/responsive.js +++ b/src/responsive.js @@ -3,10 +3,16 @@ function onLoaded() { console.log("loaded trigger"); document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera + let navs = document.querySelectorAll('.navElement'); + navs.forEach(function (element) { + element.onclick = function () { + toggleMenu(); + } + }); window.onresize = function () { resizer() }; resizer(); - if(window.innerWidth < 1200){ + if (window.innerWidth < 1200) { const e = document.querySelector(".navControl"); e.style.maxHeight = '0px'; } @@ -27,7 +33,7 @@ function resizer() { document.querySelector(".header").style.borderBottomWidth = '3px'; e.style.maxHeight = '0px'; document.querySelectorAll('.navElement *').forEach(x => { x.style.paddingTop = '.3rem'; x.style.paddingBottom = '.3rem'; x.style.fontSize = '1rem' }); - } + } } function scrollFunction() { @@ -45,13 +51,15 @@ function scrollFunction() { } export function toggleMenu() { - const e = document.querySelector(".navControl"); - const bar = document.querySelector(".header"); - if (e.style.maxHeight === '0px') { - e.style.maxHeight = `${e.scrollHeight + 10}px`; - bar.style.borderBottomWidth = '0px'; - } else { - e.style.maxHeight = '0px'; - bar.style.borderBottomWidth = '3px'; + if (window.innerWidth < 1200) { + const e = document.querySelector(".navControl"); + const bar = document.querySelector(".header"); + if (e.style.maxHeight === '0px') { + e.style.maxHeight = `${e.scrollHeight + 10}px`; + bar.style.borderBottomWidth = '0px'; + } else { + e.style.maxHeight = '0px'; + bar.style.borderBottomWidth = '3px'; + } } } \ No newline at end of file