Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile Responsiveness #105

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion _includes/nav.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav>
<nav class="open">
<div class="hex" role="img" aria-label="Navigation bar background graphic, styled like the address panel of a hex editor.">
<ol>
{%- for i in (0..256) -%}
Expand All @@ -20,4 +20,41 @@
</li>
{%- endfor -%}
</ul>

</nav>

<div class="nav-toggle hamburger-container">
<div class="hamburger-button"></div>
</div>


<script>
const responsiveNavThreshold = 500;
const navOpener = document.querySelector('.nav-toggle');
const nav = document.querySelector('nav');

const toggle = (cl, attr) => cl.contains(attr) ? cl.remove(attr) : cl.add(attr);

navOpener.addEventListener('click', () => {
toggle(nav.classList, 'open');
});

let enabled = false;

const setResponsive = () => {
if (window.innerWidth < responsiveNavThreshold) {
if (enabled) return;
enabled = true;
nav.classList.remove('open');
navOpener.classList.add('enabled');
}
else {
if (!enabled) return;
enabled = false;
nav.classList.add('open');
navOpener.classList.remove('enabled');
}
};
setResponsive();
window.addEventListener('resize', setResponsive);
</script>
5 changes: 4 additions & 1 deletion assets/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ html,
body {
margin: 0;
padding: 0;
background-color: #2c2c2c;
background-color: var(--cyber-dark-grey);
color: #ffffff;

--min-nav-inner-width: 8ch;
--nav-width: calc(max(var(--min-nav-inner-width), 10%) + 2rem);
--nav-footer-font-size: max(2.1vw, calc(0.21 * var(--min-nav-inner-width)));
--nav-footer-line-height-multiplier: 1.32;
--nav-footer-line-height: calc(var(--nav-footer-line-height-multiplier) * var(--nav-footer-font-size));
--cyber-yellow: #ffbd3f;
--cyber-dark-grey: #2c2c2c;
--arcimation: 400ms cubic-bezier(.23,1,.32,1);
}

body, p, code {
Expand Down
10 changes: 9 additions & 1 deletion assets/styles/main.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// set a margin-left on content when navbar is open
body:has(nav.open) .content {
margin-left: var(--nav-width);
}

body:has(.nav-toggle.enabled) {
padding-top: 1rem;
}

.content {
display: flex;
flex-direction: column;
justify-content: space-between;
min-height: 100vh;
margin-left: var(--nav-width);

main {
padding: 2rem 7%;
Expand Down
74 changes: 74 additions & 0 deletions assets/styles/nav.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
// when it is opened, a sliding effect will be created
nav:not(.open) {
transform: translateX(-100%);
}

.nav-toggle:not(.enabled) {
display: none;
}

.nav-toggle {
position: fixed;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
top: 0.25rem;
left: 0.25rem;
width: 2rem;
height: 2rem;
padding: 0.5rem;
font-size: 2rem;
// below means 90% cyber-yellow, 10% black
// commenting out below as hamburger button looks better without a button
// background: color-mix(in srgb, var(--cyber-yellow) 90%, black);
}

.nav-toggle:hover {
cursor: pointer;
}

/* yes this hamburger code is stolen directly from myself @ lactf ~ andrew */
/* heehee i stole this hamburger code from andrew @ acmcyber.com ~ ronak */

.hamburger-button {
&,
&::before,
&::after {
display: block;
position: absolute;
height: 4px;
width: 30px;
background-color: white;
border-radius: 2px;
transition: transform var(--arcimation);
}

&::before {
content: "";
margin-top: -8px;
}

&::after {
content: "";
margin-top: 8px;
}
}

body:has(nav.open) {
.hamburger-button::before {
margin-top: 0px;
transform: rotate(405deg);
}

.hamburger-button {
background: transparent;
}

.hamburger-button::after {
margin-top: 0px;
transform: rotate(-405deg);
}
}

nav {
--nav-inner-width: 8ch;

Expand All @@ -9,6 +82,7 @@ nav {
padding: 1rem 0rem 0rem 1.75ch;
-webkit-padding-start: 0.4rem;
width: calc(var(--nav-width) - 2rem);
transition: var(--arcimation);

div.hex {
position: absolute;
Expand Down