diff --git a/source/css/_common/outline/header/site-nav.styl b/source/css/_common/outline/header/site-nav.styl index d5e7cfc..864d1bf 100644 --- a/source/css/_common/outline/header/site-nav.styl +++ b/source/css/_common/outline/header/site-nav.styl @@ -19,10 +19,6 @@ .site-nav { +mobile() { - display: none; - } - - .site-nav-on & { - display: block; + site-nav-hide-by-default(); } } diff --git a/source/css/_mixins.styl b/source/css/_mixins.styl index cce5fc6..229d5b5 100644 --- a/source/css/_mixins.styl +++ b/source/css/_mixins.styl @@ -219,3 +219,18 @@ toggle-close($position) { } } } + +site-nav-hide-by-default() { + --scroll-height: 0; + height: 0; + overflow: hidden; + transition: height $transition-ease; + + body:not(.site-nav-on) & .animated { + animation: none; + } + + body.site-nav-on & { + height: var(--scroll-height); + } +} diff --git a/source/css/_schemes/Pisces/_menu.styl b/source/css/_schemes/Pisces/_menu.styl index 90475aa..79b1c20 100644 --- a/source/css/_schemes/Pisces/_menu.styl +++ b/source/css/_schemes/Pisces/_menu.styl @@ -1,6 +1,6 @@ .site-nav { +tablet() { - display: none; + site-nav-hide-by-default(); } } diff --git a/source/js/next-boot.js b/source/js/next-boot.js index b21daa4..2bd8a64 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -12,35 +12,8 @@ NexT.boot.registerEvents = function() { event.currentTarget.classList.toggle('toggle-close'); const siteNav = document.querySelector('.site-nav'); if (!siteNav) return; - const animateAction = document.body.classList.contains('site-nav-on'); - const height = NexT.utils.getComputedStyle(siteNav); - siteNav.style.height = animateAction ? height : 0; - const toggle = () => document.body.classList.toggle('site-nav-on'); - const begin = () => { - siteNav.style.overflow = 'hidden'; - }; - const complete = () => { - siteNav.style.overflow = ''; - siteNav.style.height = ''; - }; - window.anime(Object.assign({ - targets : siteNav, - duration: 200, - height : animateAction ? [height, 0] : [0, height], - easing : 'linear' - }, animateAction ? { - begin, - complete: () => { - complete(); - toggle(); - } - } : { - begin: () => { - begin(); - toggle(); - }, - complete - })); + siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px'); + document.body.classList.toggle('site-nav-on'); }); const duration = 200; diff --git a/source/js/utils.js b/source/js/utils.js index 4f542f6..feb30fd 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -290,17 +290,6 @@ NexT.utils = { }); }, - getComputedStyle: function(element) { - const clone = element.cloneNode(true); - clone.style.position = 'absolute'; - clone.style.visibility = 'hidden'; - clone.style.display = 'block'; - element.parentNode.appendChild(clone); - const height = clone.clientHeight; - element.parentNode.removeChild(clone); - return height; - }, - /** * Init Sidebar & TOC inner dimensions on all pages and for all schemes. * Need for Sidebar/TOC inner scrolling if content taller then viewport.