Added navigation menu animation

This commit is contained in:
Kristofers Solo 2023-01-19 18:15:44 +02:00
parent 1560d9fc71
commit eaf0a7d8ab
7 changed files with 147 additions and 243 deletions

View File

@ -0,0 +1,64 @@
:root {
--color-scale-black: #010409;
--color-scale-white: #ffffff;
--color-scale-white-transparent-7: #ffffffbc;
--color-scale-gray-0: #f0f6fc;
--color-scale-gray-1: #c9d1d9;
--color-scale-gray-2: #b1bac4;
--color-scale-gray-3: #8b949e;
--color-scale-gray-4: #6e7681;
--color-scale-gray-5: #484f58;
--color-scale-gray-6: #30363d;
--color-scale-gray-7: #21262d;
--color-scale-gray-8: #161b22;
--color-scale-gray-9: #0d1117;
--color-scale-gray-0-transparent-10: #f0f6fc1a;
--color-scale-gray-8-transparent-50: #161b2280;
--color-scale-gray-9-transparent-0: #0d111700;
--color-scale-purple-0: #eddeff;
--color-scale-purple-1: #e2c5ff;
--color-scale-purple-2: #d2a8ff;
--color-scale-purple-3: #bc8cff;
--color-scale-purple-4: #a371f7;
--color-scale-purple-5: #8957e5;
--color-scale-purple-6: #6e40c9;
--color-scale-purple-7: #553098;
--color-scale-purple-8: #3c1e70;
--color-scale-purple-9: #271052;
--color-scale-purple-4-transparent-06: #a371f70f;
--color-canvas-default: var(--color-scale-gray-9);
--color-canvas-default-transparent: var(--color-scale-gray-9-transparent-0);
--color-canvas-subtle: var(--color-scale-gray-8);
--color-border-default: var(--color-scale-gray-6);
--color-header-bg-default: var(--color-scale-gray-8);
--color-header-bg-transparent: var(--color-scale-gray-8-transparent-5);
--color-header-text: var(--color-scale-white-transparent-7);
--color-btn-text: var(--color-scale-gray-1);
--color-btn-bg: var(--color-scale-gray-7);
--color-btn-border: var(--color-scale-gray-0-transparent-1);
--color-btn-hover-bg: var(--color-scale-gray-6);
--color-btn-hover-border: var(--color-scale-gray-3);
--color-btn-active-border: var(--color-scale-gray-5);
--color-fg-default: var(--color-scale-gray-1);
--color-fg-muted: var(--color-scale-gray-3);
--color-fg-subtle: var(--color-scale-gray-4);
--color-fg-on-emphasis: var(--color-scale-white);
--color-text-hover: var(--color-fg-muted);
--color-accent-fg: var(--color-scale-purple-4);
--color-text-link: var(--color-accent-fg);
font-size: 16px;
font-family: "Roboto", arial, sans-serif;
}

View File

@ -1,68 +1,3 @@
:root {
--color-scale-black: #010409;
--color-scale-white: #ffffff;
--color-scale-white-transparent-7: #ffffffbc;
--color-scale-gray-0: #f0f6fc;
--color-scale-gray-1: #c9d1d9;
--color-scale-gray-2: #b1bac4;
--color-scale-gray-3: #8b949e;
--color-scale-gray-4: #6e7681;
--color-scale-gray-5: #484f58;
--color-scale-gray-6: #30363d;
--color-scale-gray-7: #21262d;
--color-scale-gray-8: #161b22;
--color-scale-gray-9: #0d1117;
--color-scale-gray-0-transparent-10: #f0f6fc1a;
--color-scale-gray-8-transparent-50: #161b2280;
--color-scale-gray-9-transparent-0: #0d111700;
--color-scale-purple-0: #eddeff;
--color-scale-purple-1: #e2c5ff;
--color-scale-purple-2: #d2a8ff;
--color-scale-purple-3: #bc8cff;
--color-scale-purple-4: #a371f7;
--color-scale-purple-5: #8957e5;
--color-scale-purple-6: #6e40c9;
--color-scale-purple-7: #553098;
--color-scale-purple-8: #3c1e70;
--color-scale-purple-9: #271052;
--color-scale-purple-4-transparent-06: #a371f70f;
--color-canvas-default: var(--color-scale-gray-9);
--color-canvas-default-transparent: var(--color-scale-gray-9-transparent-0);
--color-canvas-subtle: var(--color-scale-gray-8);
--color-border-default: var(--color-scale-gray-6);
--color-header-bg-default: var(--color-scale-gray-8);
--color-header-bg-transparent: var(--color-scale-gray-8-transparent-5);
--color-header-text: var(--color-scale-white-transparent-7);
--color-btn-text: var(--color-scale-gray-1);
--color-btn-bg: var(--color-scale-gray-7);
--color-btn-border: var(--color-scale-gray-0-transparent-1);
--color-btn-hover-bg: var(--color-scale-gray-6);
--color-btn-hover-border: var(--color-scale-gray-3);
--color-btn-active-border: var(--color-scale-gray-5);
--color-fg-default: var(--color-scale-gray-1);
--color-fg-muted: var(--color-scale-gray-3);
--color-fg-subtle: var(--color-scale-gray-4);
--color-fg-on-emphasis: var(--color-scale-white);
--color-text-hover: var(--color-fg-muted);
--color-accent-fg: var(--color-scale-purple-4);
--color-text-link: var(--color-accent-fg);
font-size: 16px;
font-family: "Roboto", arial, sans-serif;
}
html,
body {
color: var(--color-fg-default);
@ -89,25 +24,12 @@ body {
font-weight: 700;
}
.sr-only {
border: 0 !important;
clip: rect(1px, 1px, 1px, 1px) !important; /* 1 */
-webkit-clip-path: inset(50%) !important;
clip-path: inset(50%) !important; /* 2 */
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
white-space: nowrap !important; /* 3 */
}
/* Navigation bar */
.logo {
margin: 2rem;
width: 2rem;
margin: 1rem;
padding: 1rem;
width: 3rem;
aspect-ratio: 1;
}
@ -116,11 +38,6 @@ body {
justify-content: space-between;
}
.mobile-nav-toggle {
display: none;
cursor: pointer;
}
.primary-navigation {
background-color: var(--color-header-bg-default);
}
@ -165,23 +82,7 @@ body {
}
.mobile-nav-toggle {
display: block;
position: absolute;
z-index: 9999;
background-color: transparent;
background-image: url("../img/icons/icon-hamburger-menu.svg");
background-repeat: no-repeat;
width: 3rem;
border: 0;
aspect-ratio: 1;
top: 2rem;
right: 2rem;
}
.mobile-nav-toggle[aria-expanded="true"] {
background-color: transparent;
background-image: url("../img/icons/icon-close.svg");
background-repeat: no-repeat;
display: flex;
}
}

View File

@ -0,0 +1,63 @@
:root {
--button-width: 3rem;
--line-width: 3rem;
--line-height: 0.3rem;
--line-border-radius: calc(var(--line-height) / 2);
}
.mobile-nav-toggle {
display: none;
cursor: pointer;
justify-content: center;
align-items: center;
width: var(--button-width);
aspect-ratio: 1;
cursor: pointer;
transition: all 0.5s ease-in-out;
position: absolute;
z-index: 9999;
border: 0;
top: 1rem;
right: 1rem;
padding: 1rem;
}
.mobile-nav-toggle__line {
width: var(--line-width);
height: var(--line-height);
background: var(--color-fg-default);
border-radius: var(--line-border-radius);
transition: all 0.5s ease-in-out;
}
.mobile-nav-toggle__line::before,
.mobile-nav-toggle__line::after {
content: "";
position: absolute;
width: var(--line-width);
height: var(--line-height);
background: var(--color-fg-default);
border-radius: var(--line-border-radius);
transition: all 0.5s ease-in-out;
}
.mobile-nav-toggle__line::before {
transform: translateY(-16px);
}
.mobile-nav-toggle__line::after {
transform: translateY(16px);
}
.mobile-nav-toggle.open .mobile-nav-toggle__line {
transform: translateX(-50px);
background: transparent;
box-shadow: none;
}
.mobile-nav-toggle.open .mobile-nav-toggle__line::before {
transform: rotate(45deg) translate(35px, -35px);
}
.mobile-nav-toggle.open .mobile-nav-toggle__line::after {
transform: rotate(-45deg) translate(35px, 35px);
}

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="30"
height="30"
viewBox="0 0 7.9374998 7.9375"
version="1.1"
id="svg1771"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
sodipodi:docname="icon-close.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1773"
pagecolor="#505050"
bordercolor="#ffffff"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#505050"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="12.400673"
inkscape:cx="-0.36288353"
inkscape:cy="17.539371"
inkscape:window-width="1916"
inkscape:window-height="1055"
inkscape:window-x="1920"
inkscape:window-y="21"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1768" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<g
id="g1966"
transform="matrix(0.75757574,0.75757576,-0.75757574,0.75757576,3.96875,-2.0445077)">
<rect
style="fill:#f0f6fc;fill-opacity:1;stroke-width:0.289836;stroke-miterlimit:10000;paint-order:markers stroke fill"
id="rect234"
width="7.9375"
height="0.79374999"
x="-1.7763568e-15"
y="3.5718751"
ry="0" />
<rect
style="fill:#f0f6fc;fill-opacity:1;stroke-width:0.289836;stroke-miterlimit:10000;paint-order:markers stroke fill"
id="rect234-3"
width="0.79374999"
height="7.9375"
x="3.5718751"
y="-8.8817842e-16"
ry="0" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="30"
height="30"
viewBox="0 0 7.9374998 7.9375"
version="1.1"
id="svg5"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
sodipodi:docname="icon-hamburger-menu.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#505050"
bordercolor="#ffffff"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#505050"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="6.2003367"
inkscape:cx="-20.966603"
inkscape:cy="5.0803693"
inkscape:window-width="1916"
inkscape:window-height="1055"
inkscape:window-x="1920"
inkscape:window-y="21"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#f0f6fc;fill-opacity:1;stroke-width:0.289836;stroke-miterlimit:10000;paint-order:markers stroke fill"
id="rect234"
width="7.9375"
height="0.79374999"
x="-1.110223e-15"
y="1.3229166"
ry="0" />
<rect
style="fill:#f0f6fc;fill-opacity:1;stroke-width:0.289836;stroke-miterlimit:10000;paint-order:markers stroke fill"
id="rect234-3"
width="7.9375"
height="0.79374999"
x="-1.110223e-15"
y="3.5718751"
ry="0" />
<rect
style="fill:#f0f6fc;fill-opacity:1;stroke-width:0.289836;stroke-miterlimit:10000;paint-order:markers stroke fill"
id="rect234-6"
width="7.9375"
height="0.79374999"
x="-1.110223e-15"
y="5.8208332"
ry="0" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,13 +1,15 @@
const PRIMARY_NAV = document.querySelector(".primary-navigation")
const EMAIL = document.querySelector(".mobile-nav-toggle")
const MENU_BUTTON = document.querySelector(".mobile-nav-toggle")
EMAIL.addEventListener("click", () => {
MENU_BUTTON.addEventListener("click", () => {
const VISIBILITY = PRIMARY_NAV.getAttribute("data-visible") === "false"
if (VISIBILITY) {
PRIMARY_NAV.setAttribute("data-visible", true)
EMAIL.setAttribute("aria-expanded", true)
MENU_BUTTON.setAttribute("aria-expanded", true)
MENU_BUTTON.classList.add("open")
} else {
PRIMARY_NAV.setAttribute("data-visible", false)
EMAIL.setAttribute("aria-expanded", false)
MENU_BUTTON.setAttribute("aria-expanded", false)
MENU_BUTTON.classList.remove("open")
}
})

View File

@ -15,11 +15,17 @@
<link rel="stylesheet"
type="text/css"
href="{% static 'main/css/reset.css' %}"/>
<link rel="stylesheet"
type="text/css"
href="{% static 'main/css/colors.css' %}"/>
<link rel="stylesheet"
type="text/css"
href="{% static 'main/css/navigation_button.css' %}"/>
<link rel="stylesheet"
type="text/css"
href="{% static 'main/css/layout.css' %}"/>
{% block meta %}{% endblock %}
<script src="{% static 'main/js/navigation.js' %}" defer></script>
{% block meta %}{% endblock %}
</head>
<body>
<header class="primary-header flex">
@ -28,11 +34,9 @@
<img src="{% static 'main/img/icons/logo.svg' %}" alt="logo" class="logo">
</a>
</div>
<button class="mobile-nav-toggle"
aria-controls="primary-navigation"
aria-expanded="false">
<span class="sr-only">Menu</span>
</button>
<div class="mobile-nav-toggle">
<div class="mobile-nav-toggle__line"></div>
</div>
<nav>
<ul id="primary-navigation"
class="primary-navigation flex"