Change mobile menu technique to button with JS

This commit is contained in:
Alice Gaudon 2020-07-06 12:03:45 +02:00
parent b30719110a
commit 27b53bf04d
4 changed files with 43 additions and 13 deletions

View File

@ -2,6 +2,7 @@ import './external_links';
import './message_icons';
import './forms';
import './copyable_text';
import './main_menu';
import '../sass/app.scss';

17
assets/js/main_menu.js Normal file
View File

@ -0,0 +1,17 @@
document.addEventListener('DOMContentLoaded', () => {
const menuButton = document.getElementById('menu-button');
const mainMenu = document.getElementById('main-menu');
menuButton.addEventListener('click', (e) => {
e.stopPropagation();
mainMenu.classList.toggle('open');
});
mainMenu.addEventListener('click', (e) => {
e.stopPropagation();
});
document.addEventListener('click', () => {
mainMenu.classList.remove('open');
});
});

View File

@ -76,13 +76,13 @@ header {
}
}
a:hover {
a:hover, a:active {
background-color: rgba(255, 255, 255, 0.07);
}
}
}
.hamburger {
#menu-button {
display: none;
}
}
@ -90,17 +90,29 @@ header {
@media (max-width: $menuLayoutSwitchTreshold) {
flex-direction: row-reverse;
.logo {
padding: 0 16px 0 8px;
font-size: 24px;
img {
margin-right: 8px;
}
}
nav {
flex: 1;
.hamburger {
#menu-button {
display: block;
margin: 0;
padding: 0 16px;
line-height: $headerHeight;
cursor: pointer;
background: transparent;
border-radius: 0;
width: max-content;
&:hover {
width: auto;
.feather {
--icon-size: 28px;
margin: 0 8px;
}
}
@ -112,10 +124,10 @@ header {
transition: transform ease-out 150ms;
background-color: $headerBackground;
}
.hamburger:hover + ul, ul:hover {
transform: translateX(0%);
&.open {
transform: translateX(0%);
}
}
}
}

View File

@ -14,8 +14,8 @@
{% block header %}
<a href="/" class="logo"><img src="/img/logo.svg" alt="Logo"> {{ app.name }}</a>
<nav>
<div class="hamburger"><i data-feather="menu"></i></div>
<ul>
<button id="menu-button"><i data-feather="menu"></i></button>
<ul id="main-menu">
<li><a href="{{ route('about') }}"><i data-feather="info"></i> About</a></li>
</ul>
</nav>