From: Dan Allen Date: Wed, 30 Dec 2020 10:16:06 +0000 (-0700) Subject: scroll panel to bring children into view when expanding nav item X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1f697cac5b05fb67143a18466fb40dd36f811b8e;p=eg-antora.git scroll panel to bring children into view when expanding nav item --- diff --git a/src/js/01-nav.js b/src/js/01-nav.js index 466dd7f..95f5163 100644 --- a/src/js/01-nav.js +++ b/src/js/01-nav.js @@ -100,7 +100,13 @@ } function toggleActive () { - this.classList.toggle('is-active') + if (this.classList.toggle('is-active')) { + var padding = parseFloat(window.getComputedStyle(this).marginTop) + var rect = this.getBoundingClientRect() + var menuPanelRect = menuPanel.getBoundingClientRect() + var overflowY = (rect.bottom - menuPanelRect.top - menuPanelRect.height + padding).toFixed() + if (overflowY > 0) menuPanel.scrollTop += Math.min((rect.top - menuPanelRect.top - padding).toFixed(), overflowY) + } } function showNav (e) {