Skip to content

Commit

Permalink
Suppor transparent navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
markdumay committed Feb 16, 2023
1 parent d4bf047 commit d12cdc7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
16 changes: 16 additions & 0 deletions assets/js/navbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const navbar = document.querySelector('.navbar');
const toggler = document.getElementById('main-nav-toggler');

// set the navbar background color to opaque when scrolling past a breakpoint
window.onscroll = () => {
if (window.scrollY > 75) {
navbar.classList.add('nav-active');
} else {
navbar.classList.remove('nav-active');
}
}

// set the navbar background color to opaque when expanded
toggler.onclick = () => {
navbar.classList.toggle('navbar-expanded');
}
9 changes: 9 additions & 0 deletions assets/scss/components/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

// Source: https://jsfiddle.net/njhgr40m/

.navbar {
transition: 0.5s ease-in-out;
background-color: none;
}

.nav-active, .navbar-expanded {
background-color: var(--bs-body-bg);
}

/* Remove border from toggler */
.navbar-toggler {
border: 0 !important;
Expand Down
2 changes: 2 additions & 0 deletions i18n/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
translation: "Dunkel"
- id: colorAuto
translation: "Automatisch"
- id: toggleMainNav
translation: "Hauptmenü anzuzeigen oder auszublenden"

# 404 page
- id: pageNotFound
Expand Down
4 changes: 3 additions & 1 deletion i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- id: paginationLast
translation: "Last"
- id: toggleSidebar
translation: "Toggle sidebar navigation"
translation: "Toggle sidebar navigation"
- id: colorMode
translation: "Color mode"
- id: colorLight
Expand All @@ -63,6 +63,8 @@
translation: "Dark"
- id: colorAuto
translation: "Auto"
- id: toggleMainNav
translation: "Toggle main navigation"

# 404 page
- id: pageNotFound
Expand Down
4 changes: 3 additions & 1 deletion i18n/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- id: paginationLast
translation: "Laatste"
- id: toggleSidebar
translation: "Toon of verberg navigatie"
translation: "Toon of verberg navigatie"
- id: colorMode
translation: "Modus"
- id: colorLight
Expand All @@ -63,6 +63,8 @@
translation: "Donker"
- id: colorAuto
translation: "Automatisch"
- id: toggleMainNav
translation: "Toon of verberg hoofdnavigatie"

# 404 page
- id: pageNotFound
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{- partial "assets/navbar.html" (dict
"page" .
"fixed" (string .Site.Params.navigation.fixed)
"color" (default "white" .Site.Params.navigation.color)
"color" (.Site.Params.navigation.color)
"style" (default "light" .Site.Params.navigation.style))
-}}
</div>
Expand Down
5 changes: 2 additions & 3 deletions layouts/partials/assets/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@
</a>

<!-- Insert main navigation toggler -->
<button class="navbar-toggler collapsed me-n3" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent-{{ $id }}"
aria-controls="navbarSupportedContent-{{ $id }}" aria-expanded="false" aria-label="Toggle main navigation">
<!-- TODO: add i18n translation -->
<button id="main-nav-toggler" class="navbar-toggler collapsed me-n3" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent-{{ $id }}"
aria-controls="navbarSupportedContent-{{ $id }}" aria-expanded="false" aria-label="{{ T "toggleMainNav" }}">
<span class="toggler-icon top-bar emphasis"></span>
<span class="toggler-icon middle-bar emphasis"></span>
<span class="toggler-icon bottom-bar emphasis"></span>
Expand Down

0 comments on commit d12cdc7

Please sign in to comment.