Skip to content

Commit d952774

Browse files
committed
Use hamburger menu for mobile devices
1 parent c14d976 commit d952774

File tree

1 file changed

+101
-4
lines changed

1 file changed

+101
-4
lines changed

src/layouts/Layout.astro

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,43 @@ const { title = "Immortals Robotics Team" } = Astro.props;
1515
<meta name="generator" content={Astro.generator} />
1616
<title>{title} | Immortals SSL</title>
1717
<meta name="description" content="Immortals Small Size League robotics team, founded in 2008 and participating in RoboCup competitions worldwide." />
18+
<script>
19+
// Toggle menu functionality
20+
document.addEventListener('DOMContentLoaded', () => {
21+
const hamburger = document.querySelector('.hamburger-menu');
22+
const navLinks = document.querySelector('.nav-links');
23+
24+
if (hamburger && navLinks) {
25+
hamburger.addEventListener('click', () => {
26+
hamburger.classList.toggle('active');
27+
navLinks.classList.toggle('active');
28+
document.body.classList.toggle('menu-open');
29+
});
30+
31+
// Close menu when a link is clicked
32+
const links = navLinks.querySelectorAll('a');
33+
links.forEach(link => {
34+
link.addEventListener('click', () => {
35+
hamburger.classList.remove('active');
36+
navLinks.classList.remove('active');
37+
document.body.classList.remove('menu-open');
38+
});
39+
});
40+
}
41+
});
42+
</script>
1843
</head>
1944
<body>
2045
<header>
2146
<nav>
2247
<div class="logo">
2348
<a href="/"><img src="/assets/logo.png" alt="Immortals Logo" height="60" /></a>
2449
</div>
50+
<button class="hamburger-menu" aria-label="Toggle navigation menu">
51+
<span></span>
52+
<span></span>
53+
<span></span>
54+
</button>
2555
<ul class="nav-links">
2656
<li><a href="/">Home</a></li>
2757
<li><a href="/about">About</a></li>
@@ -161,16 +191,83 @@ const { title = "Immortals Robotics Team" } = Astro.props;
161191
text-decoration: none;
162192
}
163193

194+
/* Hamburger menu styles */
195+
.hamburger-menu {
196+
display: none;
197+
background: none;
198+
border: none;
199+
cursor: pointer;
200+
padding: 0;
201+
z-index: 10;
202+
}
203+
204+
.hamburger-menu span {
205+
display: block;
206+
width: 25px;
207+
height: 3px;
208+
background-color: var(--light);
209+
margin: 5px 0;
210+
transition: all 0.3s ease;
211+
border-radius: 3px;
212+
}
213+
164214
@media (max-width: 768px) {
165215
nav {
166-
flex-direction: column;
167-
gap: 1rem;
216+
justify-content: space-between;
217+
position: relative;
218+
}
219+
220+
.hamburger-menu {
221+
display: block;
168222
}
169223

170224
.nav-links {
225+
position: fixed;
226+
top: 0;
227+
right: -100%;
228+
width: 70%;
229+
max-width: 300px;
230+
height: 100vh;
231+
background-color: var(--primary);
171232
flex-direction: column;
172-
align-items: center;
173-
gap: 0.5rem;
233+
padding: 80px 30px 30px;
234+
transition: right 0.3s ease;
235+
box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
236+
z-index: 5;
237+
justify-content: flex-start;
238+
align-items: flex-start;
239+
}
240+
241+
.nav-links.active {
242+
right: 0;
243+
}
244+
245+
.nav-links li {
246+
width: 100%;
247+
margin-bottom: 1.5rem;
248+
}
249+
250+
.nav-links a {
251+
display: block;
252+
font-size: 1.1rem;
253+
}
254+
255+
/* Hamburger menu animation */
256+
.hamburger-menu.active span:nth-child(1) {
257+
transform: rotate(45deg) translate(5px, 5px);
258+
}
259+
260+
.hamburger-menu.active span:nth-child(2) {
261+
opacity: 0;
262+
}
263+
264+
.hamburger-menu.active span:nth-child(3) {
265+
transform: rotate(-45deg) translate(7px, -7px);
266+
}
267+
268+
/* Prevent scrolling when menu is open */
269+
body.menu-open {
270+
overflow: hidden;
174271
}
175272
}
176273
</style>

0 commit comments

Comments
 (0)