Skip to content

Commit d1f9ea4

Browse files
author
zixuan-liu-17
committed
Fix mobile menu issues and implement improved dropdown functionality
- Replace HTML5 details/summary with JavaScript-controlled dropdown - Add dynamic parent container expansion when menu is open - Improve mobile menu positioning and styling - Add smooth transitions and icon rotation animations - Fix mobile menu being hidden behind other elements
1 parent 5e5a93e commit d1f9ea4

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

_includes/footer.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,42 @@
1010

1111
<!-- <script src="{{ "/assets/vendor/jquery/dist/jquery.min.js" | relative_url}}"></script> -->
1212
<script>anchors.add('.org-type h4');</script>
13+
14+
<!-- Mobile menu toggle functionality -->
15+
<script>
16+
document.addEventListener('DOMContentLoaded', function() {
17+
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
18+
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
19+
const headerLayout = document.querySelector('.header-layout');
20+
21+
if (mobileMenuBtn && mobileMenuToggle && headerLayout) {
22+
mobileMenuBtn.addEventListener('click', function() {
23+
const isOpen = mobileMenuToggle.classList.contains('menu-open');
24+
25+
if (isOpen) {
26+
// 关闭菜单
27+
mobileMenuToggle.classList.remove('menu-open');
28+
headerLayout.classList.remove('menu-expanded');
29+
mobileMenuBtn.setAttribute('aria-expanded', 'false');
30+
} else {
31+
// 打开菜单
32+
mobileMenuToggle.classList.add('menu-open');
33+
headerLayout.classList.add('menu-expanded');
34+
mobileMenuBtn.setAttribute('aria-expanded', 'true');
35+
}
36+
});
37+
38+
// Close menu when clicking outside
39+
document.addEventListener('click', function(event) {
40+
if (!mobileMenuToggle.contains(event.target)) {
41+
mobileMenuToggle.classList.remove('menu-open');
42+
headerLayout.classList.remove('menu-expanded');
43+
mobileMenuBtn.setAttribute('aria-expanded', 'false');
44+
}
45+
});
46+
}
47+
});
48+
</script>
1349
{% if page.url == "/community/" %}
1450
<script src="{{ "/assets/js/community.js" | relative_url}}"></script>
1551
{% elsif page.url == "/" %}

_includes/header.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
<a href="{{ "/" | relative_url}}" style="font-size: 2.5em; font-weight: bold;">OSeMOSYS</a>
2929
</div>
3030
<!-- Mobile menu toggle -->
31-
<details class="mobile-menu-toggle d-md-none">
32-
<summary class="mobile-menu-btn" aria-haspopup="true">
31+
<div class="mobile-menu-toggle d-md-none">
32+
<button class="mobile-menu-btn" aria-haspopup="true" aria-expanded="false">
3333
{% octicon chevron-down height:20 class:"mobile-menu-icon" aria-label:menu %}
3434
<span class="mobile-menu-text">Menu</span>
35-
</summary>
35+
</button>
3636

3737
<!-- Mobile navigation - shown when menu is open -->
3838
<ul class="mobile-navigation">
3939
{% include subpage_links.html %}
4040
</ul>
41-
</details>
41+
</div>
4242
</div>
4343

4444
<!-- Navigation -->

assets/css/custom.scss

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ body {
88
.intro-title {
99
color: #1e3a8a !important; // Deep blue for titles
1010
font-weight: 200;
11+
margin-top: 10px;
1112
}
1213

1314
.intro-text {
@@ -103,6 +104,7 @@ $header-accent-color: #3490dc; // Sky blue accent color
103104
position: relative;
104105
min-height: 100px; // Cleaner, more compact
105106
padding: 1.5rem 0;
107+
transition: padding-bottom 0.3s ease;
106108

107109
// Add background image only to header
108110
// &::before {
@@ -125,6 +127,13 @@ $header-accent-color: #3490dc; // Sky blue accent color
125127
min-height: auto; //
126128
padding: 1rem 0 1rem 0; //
127129
}
130+
131+
// 当移动菜单展开时,为父容器增加底部空间
132+
&.menu-expanded {
133+
@media (max-width: 768px) {
134+
padding-bottom: 12rem; // 为展开的菜单留出空间
135+
}
136+
}
128137
}
129138

130139
.mobile-menu-toggle[open] {
@@ -773,7 +782,7 @@ td.does-not-support { color: $red-500; }
773782

774783
// Mobile navigation styling
775784
.mobile-navigation {
776-
margin: 0.5rem 0 0 0;
785+
margin: 0.5rem 0.5rem 0 0;
777786
padding: 0;
778787
list-style: none;
779788
display: flex; // 改为flex,通过max-height控制显示
@@ -785,8 +794,8 @@ td.does-not-support { color: $red-500; }
785794
border-radius: 12px;
786795
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
787796
backdrop-filter: blur(10px);
788-
position: relative;
789-
z-index: 9999;
797+
position: absolute;
798+
z-index: 10001;
790799
max-height: 0;
791800
overflow: hidden;
792801
transition: all 0.3s ease-in-out;
@@ -831,15 +840,16 @@ td.does-not-support { color: $red-500; }
831840
}
832841

833842
// Show mobile navigation when menu is open
834-
.mobile-menu-toggle[open] .mobile-navigation {
843+
.mobile-menu-toggle.menu-open .mobile-navigation {
835844
display: flex;
836-
<<<<<<< HEAD
837845
max-height: 500px; // 设置最大高度以允许展开
838846
padding: 0.75rem;
839847
margin-top: 0.5rem;
840848
opacity: 1;
841849
transform: translateY(0);
842850
}
843-
=======
851+
852+
// Rotate the menu icon when open
853+
.mobile-menu-toggle.menu-open .mobile-menu-icon {
854+
transform: rotate(180deg);
844855
}
845-
>>>>>>> 1b5d3b4b640b9657d2ef1f1e2f3510d4772908b4

0 commit comments

Comments
 (0)