adjust height of nav panel when activating, if necessary
authorDan Allen <dan@opendevise.com>
Sat, 12 Dec 2020 23:27:48 +0000 (16:27 -0700)
committerDan Allen <dan@opendevise.com>
Sat, 12 Dec 2020 23:27:48 +0000 (16:27 -0700)
src/js/01-nav.js

index c73a808..a31d820 100644 (file)
 
   function showNav (e) {
     if (navToggle.classList.contains('is-active')) return hideNav(e)
+    var navBounds = nav.getBoundingClientRect()
+    var expectedNavHeight = window.innerHeight - Math.round(navBounds.top)
+    if (Math.round(navBounds.height) !== expectedNavHeight) nav.style.height = expectedNavHeight + 'px'
     var html = document.documentElement
     html.classList.add('is-clipped--nav')
     navToggle.classList.add('is-active')
 
   function findNextElement (from, selector) {
     var el = from.nextElementSibling
-    if (!el) return
-    return selector ? el[el.matches ? 'matches' : 'msMatchesSelector'](selector) && el : el
+    return el && selector ? el[el.matches ? 'matches' : 'msMatchesSelector'](selector) && el : el
   }
 })()