minor refactoring
authorDan Allen <dan@opendevise.com>
Sun, 20 Dec 2020 23:33:00 +0000 (16:33 -0700)
committerDan Allen <dan@opendevise.com>
Sun, 20 Dec 2020 23:33:00 +0000 (16:33 -0700)
src/js/01-nav.js

index ab68291..0b4c5bf 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'
+    trapEvent(e)
     var html = document.documentElement
     html.classList.add('is-clipped--nav')
     navToggle.classList.add('is-active')
     navContainer.classList.add('is-active')
+    var bounds = nav.getBoundingClientRect()
+    var expectedHeight = window.innerHeight - Math.round(bounds.top)
+    if (Math.round(bounds.height) !== expectedHeight) nav.style.height = expectedHeight + 'px'
     html.addEventListener('click', hideNav)
-    trapEvent(e)
   }
 
   function hideNav (e) {
+    trapEvent(e)
     var html = document.documentElement
     html.classList.remove('is-clipped--nav')
     navToggle.classList.remove('is-active')
     navContainer.classList.remove('is-active')
     html.removeEventListener('click', hideNav)
-    trapEvent(e)
   }
 
   function trapEvent (e) {