Skip to content

Enable navigation on mobile devices #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/css/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,34 @@ body {
display: none;
}

.navbar-sub:not(.is-active) {
max-height: 0;
padding: 0;
}

.navbar-sub {
display: none;
position: fixed;
top: var(--navbar-height);
width: 100%;
height: auto;
max-height: calc(100vh - var(--navbar-height));
overflow-y: scroll;
z-index: 4;
transition: max-height 0.2s ease, padding 0.2s ease;
}

.navbar-sub .container {
flex-direction: column;
}

.navbar-sub .drop-down-content {
display: inherit;
position: inherit;
top: inherit;
left: inherit;
padding-top: 7px;
padding-bottom: 0;
box-shadow: inherit;
}

.navbar-brand .navbar-item {
Expand Down
1 change: 1 addition & 0 deletions src/js/01-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var SECT_CLASS_RX = /^sect(\d)$/

var navContainer = document.querySelector('.nav-container')
if (!navContainer) return
var navToggle = document.querySelector('.nav-toggle')

navToggle.addEventListener('click', showNav)
Expand Down
7 changes: 1 addition & 6 deletions src/js/05-mobile-navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
document.documentElement.classList.toggle('is-clipped--navbar')
this.classList.toggle('is-active')
var menu = document.getElementById(this.dataset.target)
if (menu.classList.toggle('is-active')) {
menu.style.maxHeight = ''
var expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top)
var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10)
if (actualMaxHeight !== expectedMaxHeight) menu.style.maxHeight = expectedMaxHeight + 'px'
}
menu.classList.toggle('is-active')
}
})()
4 changes: 2 additions & 2 deletions src/partials/header-content.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>
{{/if}}
<button class="navbar-burger" data-target="topbar-nav">
<button class="navbar-burger" data-target="navbar-sub">
<span></span>
<span></span>
<span></span>
Expand All @@ -22,7 +22,7 @@
</div>
</div>
</nav>
<nav class="navbar-sub">
<nav id="navbar-sub" class="navbar-sub">
<div class="container">
{{> navbar}}

Expand Down