Skip to content

Commit 41b7b1e

Browse files
Merge pull request #6 from stackabletech/mobile-nav-css-only
Enable navigation on mobile devices
2 parents 7a73d20 + 84aa092 commit 41b7b1e

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

src/css/header.css

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,34 @@ body {
267267
display: none;
268268
}
269269

270+
.navbar-sub:not(.is-active) {
271+
max-height: 0;
272+
padding: 0;
273+
}
274+
270275
.navbar-sub {
271-
display: none;
276+
position: fixed;
277+
top: var(--navbar-height);
278+
width: 100%;
279+
height: auto;
280+
max-height: calc(100vh - var(--navbar-height));
281+
overflow-y: scroll;
282+
z-index: 4;
283+
transition: max-height 0.2s ease, padding 0.2s ease;
284+
}
285+
286+
.navbar-sub .container {
287+
flex-direction: column;
288+
}
289+
290+
.navbar-sub .drop-down-content {
291+
display: inherit;
292+
position: inherit;
293+
top: inherit;
294+
left: inherit;
295+
padding-top: 7px;
296+
padding-bottom: 0;
297+
box-shadow: inherit;
272298
}
273299

274300
.navbar-brand .navbar-item {

src/js/01-nav.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
var SECT_CLASS_RX = /^sect(\d)$/
55

66
var navContainer = document.querySelector('.nav-container')
7+
if (!navContainer) return
78
var navToggle = document.querySelector('.nav-toggle')
89

910
navToggle.addEventListener('click', showNav)

src/js/05-mobile-navbar.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
document.documentElement.classList.toggle('is-clipped--navbar')
1111
this.classList.toggle('is-active')
1212
var menu = document.getElementById(this.dataset.target)
13-
if (menu.classList.toggle('is-active')) {
14-
menu.style.maxHeight = ''
15-
var expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top)
16-
var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10)
17-
if (actualMaxHeight !== expectedMaxHeight) menu.style.maxHeight = expectedMaxHeight + 'px'
18-
}
13+
menu.classList.toggle('is-active')
1914
}
2015
})()

src/partials/header-content.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212
</div>
1313
{{/if}}
14-
<button class="navbar-burger" data-target="topbar-nav">
14+
<button class="navbar-burger" data-target="navbar-sub">
1515
<span></span>
1616
<span></span>
1717
<span></span>
@@ -22,7 +22,7 @@
2222
</div>
2323
</div>
2424
</nav>
25-
<nav class="navbar-sub">
25+
<nav id="navbar-sub" class="navbar-sub">
2626
<div class="container">
2727
{{> navbar}}
2828

0 commit comments

Comments
 (0)