make correction for view height when opening navbar menu on mobile
authorDan Allen <dan@opendevise.com>
Mon, 21 Dec 2020 00:20:27 +0000 (17:20 -0700)
committerDan Allen <dan@opendevise.com>
Mon, 21 Dec 2020 00:20:27 +0000 (17:20 -0700)
src/js/05-mobile-navbar.js

index 17f0452..b718738 100644 (file)
@@ -7,8 +7,14 @@
 
   function toggleNavbarMenu (e) {
     e.stopPropagation() // trap event
-    this.classList.toggle('is-active')
-    document.getElementById(this.dataset.target).classList.toggle('is-active')
     document.documentElement.classList.toggle('is-clipped--navbar')
+    this.classList.toggle('is-active')
+    var menu = document.getElementById(this.dataset.target)
+    if (menu.classList.toggle('is-active')) {
+      menu.style.maxHeight = ''
+      var expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top)
+      var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight)
+      if (actualMaxHeight !== expectedMaxHeight) menu.style.maxHeight = expectedMaxHeight + 'px'
+    }
   }
 })()