new mobile menu

This commit is contained in:
Jeppe Ernst 2018-02-05 23:17:52 +01:00
parent a2b2dd8718
commit dc99e00562
4 changed files with 75 additions and 12 deletions

View File

@ -11,6 +11,6 @@
<footer> <footer>
<!-- Last generated at {{ site.time | date_to_rfc822 }} --> <!-- Last generated at {{ site.time | date_to_rfc822 }} -->
</footer> </footer>
<script type="text/javascript" src="{{ site.url }}/assets/js/main.js"></script> <script type="text/javascript" src="{{ site.baseurl }}/assets/js/main.js"></script>
</body> </body>
</html> </html>

View File

@ -18,7 +18,17 @@ layout: default
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
<div class="right"></div> <div class="right">
<input type="checkbox" id="show-menu" role="button">
<label for="show-menu" class="show-menu"></label>
<ul>
{% for section in page.sections %}
{% if section.link %}
<li><a class="mobileLink" href="#{{ section.id }}" data-link-for="{{ section.id }}">{{ section.link }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
</nav> </nav>
{% endif %} {% endif %}
{% if section.id != "faq" %} {% if section.id != "faq" %}

View File

@ -9,14 +9,13 @@
nav { nav {
display: flex; display: flex;
background: #555; background: #555;
position: absolute;
position: fixed; position: fixed;
z-index: 1000; z-index: 1000;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
overflow-x: auto; //overflow-x: auto;
overflow-y: hidden; //overflow-y: hidden;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
white-space: nowrap; white-space: nowrap;
.js & { .js & {
@ -32,22 +31,66 @@ nav {
} }
} }
.center { .center {
float: left; a {
display: none;
&[data-link-for="wannahelp"] {
display: inline-block;
background: $background-alternative;
animation: nav-link-pulse 2s linear infinite;
}
}
} }
a { a, label {
display: inline-block; display: inline-block;
padding: 10px; padding: 10px;
box-shadow: none; box-shadow: none;
font-weight: normal; font-weight: normal;
&[data-link-for="wannahelp"]{
background: $background-alternative;
animation: nav-link-pulse 2s linear infinite;
}
} }
.left, .right { .left, .right {
flex: 1; flex: 1;
} }
.right {
text-align: right;
input[type=checkbox]{
display: none;
}
label:before {
content: "Menu";
}
input[type=checkbox]:checked ~ label {
background: #ec2727;
background: $background-alternative;
width: 30px;
text-align: center;
padding: 3px;
font-size: 30px;
&:before {
content: "X";
}
}
ul {
display: none;
li a {
display: block;
}
}
input[type=checkbox]:checked ~ ul {
position: absolute;
left: 0;
width: 100%;
display: block;
background: #555;
text-align: center;
}
}
@include media-breakpoint-up(sm) {
.right label {
display: none;
}
.center a {
display: inline-block;
}
}
} }
@keyframes nav-link-pulse { @keyframes nav-link-pulse {

View File

@ -1,2 +1,12 @@
document.documentElement.classList.remove("no-js"); document.documentElement.classList.remove("no-js");
document.documentElement.classList.add("js"); document.documentElement.classList.add("js");
function closeMobileMenu(){
var menu = document.getElementById("show-menu");
menu.checked = false;
}
var mobileLinks = document.getElementsByClassName("mobileLink");
for (var i = 0; i < mobileLinks.length; i++) {
mobileLinks[i].addEventListener('click', closeMobileMenu);
}