Skip to content

Commit 316917b

Browse files
authored
resolves #70 scroll panel to bring children into view when expanding nav item (PR #71)
1 parent 71ab0a8 commit 316917b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/js/01-nav.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@
114114
}
115115

116116
function toggleActive () {
117-
this.classList.toggle('is-active')
117+
if (this.classList.toggle('is-active')) {
118+
var padding = parseFloat(window.getComputedStyle(this).marginTop)
119+
var rect = this.getBoundingClientRect()
120+
var menuPanelRect = menuPanel.getBoundingClientRect()
121+
var overflowY = (rect.bottom - menuPanelRect.top - menuPanelRect.height + padding).toFixed()
122+
if (overflowY > 0) menuPanel.scrollTop += Math.min((rect.top - menuPanelRect.top - padding).toFixed(), overflowY)
123+
}
118124
}
119125

120126
function showNav (e) {

0 commit comments

Comments
 (0)