|
3 | 3 | <header class="bg-white/75 backdrop-blur border-b border-slate-200 sticky top-0 z-50"> |
4 | 4 | <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> |
5 | 5 | <div class="flex items-center justify-between h-16"> |
| 6 | + <!-- Logo --> |
6 | 7 | <div class="flex items-center gap-4"> |
7 | 8 | <a href="/" class="flex items-center gap-3"> |
8 | 9 | <img |
9 | 10 | src="/assets/logos/logo.png" |
10 | 11 | alt="CVEO课题组logo" |
| 12 | + width="128" |
| 13 | + height="40" |
11 | 14 | class="w-32 h-auto rounded-lg shadow-sm hover:shadow-md transition-shadow" |
| 15 | + loading="eager" |
| 16 | + decoding="async" |
12 | 17 | /> |
13 | 18 | <span class="font-semibold text-brand-900 text-lg hidden md:inline">CVEO课题组</span> |
14 | 19 | </a> |
15 | 20 | </div> |
16 | | - <nav class="flex items-center gap-6 text-sm" id="main-nav"> |
17 | | - <a href="/" class="text-slate-700 hover:text-brand-900">首页</a> |
18 | | - <a href="#news" class="text-slate-700 hover:text-brand-900">新闻动态</a> |
19 | | - <a href="#research" class="text-slate-700 hover:text-brand-900">科研成果</a> |
20 | | - <a href="/team" class="text-slate-700 hover:text-brand-900">团队成员</a> |
21 | | - <a href="/research-projects" class="text-slate-700 hover:text-brand-900">科研项目</a> |
22 | | - <a href="/collaboration" class="text-slate-700 hover:text-brand-900">合作平台</a> |
23 | | - <!-- <a href="/en" class="text-slate-700 hover:text-brand-700">EN</a> --> |
| 21 | + |
| 22 | + <!-- Desktop Navigation --> |
| 23 | + <nav class="hidden md:flex items-center gap-6 text-sm" id="main-nav"> |
| 24 | + <a href="/" class="text-slate-700 hover:text-brand-900 transition-colors">首页</a> |
| 25 | + <a href="#news" class="text-slate-700 hover:text-brand-900 transition-colors">新闻动态</a> |
| 26 | + <a href="#research" class="text-slate-700 hover:text-brand-900 transition-colors">科研成果</a> |
| 27 | + <a href="/team" class="text-slate-700 hover:text-brand-900 transition-colors">团队成员</a> |
| 28 | + <a href="/research-projects" class="text-slate-700 hover:text-brand-900 transition-colors">科研项目</a> |
| 29 | + <a href="/collaboration" class="text-slate-700 hover:text-brand-900 transition-colors">合作平台</a> |
24 | 30 | </nav> |
| 31 | + |
| 32 | + <!-- Mobile Menu Button --> |
| 33 | + <button |
| 34 | + type="button" |
| 35 | + id="mobile-menu-btn" |
| 36 | + class="md:hidden p-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-100 transition-colors" |
| 37 | + aria-label="打开菜单" |
| 38 | + aria-expanded="false" |
| 39 | + > |
| 40 | + <svg id="menu-icon-open" class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 41 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/> |
| 42 | + </svg> |
| 43 | + <svg id="menu-icon-close" class="w-6 h-6 hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 44 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/> |
| 45 | + </svg> |
| 46 | + </button> |
25 | 47 | </div> |
| 48 | + |
| 49 | + <!-- Mobile Navigation --> |
| 50 | + <nav |
| 51 | + id="mobile-nav" |
| 52 | + class="hidden md:hidden py-4 border-t border-slate-200" |
| 53 | + aria-label="移动端导航" |
| 54 | + > |
| 55 | + <div class="flex flex-col space-y-2"> |
| 56 | + <a href="/" class="px-3 py-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-50 transition-colors">首页</a> |
| 57 | + <a href="#news" class="px-3 py-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-50 transition-colors mobile-anchor">新闻动态</a> |
| 58 | + <a href="#research" class="px-3 py-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-50 transition-colors mobile-anchor">科研成果</a> |
| 59 | + <a href="/team" class="px-3 py-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-50 transition-colors">团队成员</a> |
| 60 | + <a href="/research-projects" class="px-3 py-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-50 transition-colors">科研项目</a> |
| 61 | + <a href="/collaboration" class="px-3 py-2 rounded-lg text-slate-700 hover:text-brand-900 hover:bg-slate-50 transition-colors">合作平台</a> |
| 62 | + </div> |
| 63 | + </nav> |
26 | 64 | </div> |
27 | 65 | </header> |
28 | 66 |
|
29 | 67 | <script> |
30 | 68 | function setupNav() { |
31 | 69 | const nav = document.getElementById('main-nav'); |
32 | | - if (!nav) return; |
| 70 | + const mobileNav = document.getElementById('mobile-nav'); |
| 71 | + const mobileMenuBtn = document.getElementById('mobile-menu-btn'); |
| 72 | + const menuIconOpen = document.getElementById('menu-icon-open'); |
| 73 | + const menuIconClose = document.getElementById('menu-icon-close'); |
| 74 | + |
| 75 | + if (!nav || !mobileNav || !mobileMenuBtn) return; |
| 76 | + |
| 77 | + // Mobile menu toggle |
| 78 | + let isMenuOpen = false; |
| 79 | + |
| 80 | + function toggleMenu() { |
| 81 | + isMenuOpen = !isMenuOpen; |
| 82 | + mobileNav.classList.toggle('hidden', !isMenuOpen); |
| 83 | + menuIconOpen?.classList.toggle('hidden', isMenuOpen); |
| 84 | + menuIconClose?.classList.toggle('hidden', !isMenuOpen); |
| 85 | + mobileMenuBtn.setAttribute('aria-expanded', isMenuOpen.toString()); |
| 86 | + } |
| 87 | + |
| 88 | + function closeMenu() { |
| 89 | + if (isMenuOpen) { |
| 90 | + isMenuOpen = false; |
| 91 | + mobileNav.classList.add('hidden'); |
| 92 | + menuIconOpen?.classList.remove('hidden'); |
| 93 | + menuIconClose?.classList.add('hidden'); |
| 94 | + mobileMenuBtn.setAttribute('aria-expanded', 'false'); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + mobileMenuBtn.addEventListener('click', toggleMenu); |
| 99 | + |
| 100 | + // Close menu when clicking on mobile nav links |
| 101 | + const mobileLinks = mobileNav.querySelectorAll('a'); |
| 102 | + mobileLinks.forEach(link => { |
| 103 | + link.addEventListener('click', () => { |
| 104 | + closeMenu(); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + // Close menu when clicking outside |
| 109 | + document.addEventListener('click', (e) => { |
| 110 | + const target = e.target; |
| 111 | + if (!mobileNav.contains(target) && !mobileMenuBtn.contains(target)) { |
| 112 | + closeMenu(); |
| 113 | + } |
| 114 | + }); |
33 | 115 |
|
| 116 | + // Desktop nav anchor links |
34 | 117 | const links = nav.querySelectorAll('a'); |
35 | 118 | const isHomePage = window.location.pathname === '/' || window.location.pathname === '/index.html'; |
36 | 119 |
|
|
44 | 127 | (targetId === 'teams' ? document.getElementById('team') : null); |
45 | 128 |
|
46 | 129 | if (isHomePage) { |
47 | | - // On homepage, let the default anchor jump work (BaseLayout has scroll-smooth) |
48 | 130 | if (targetId === 'teams') { |
49 | 131 | e.preventDefault(); |
50 | 132 | document.getElementById('team')?.scrollIntoView({ behavior: 'smooth' }); |
51 | 133 | } |
52 | 134 | } else { |
53 | | - // On non-homepage |
54 | 135 | if (targetElement) { |
55 | | - // Target exists on current page |
56 | 136 | e.preventDefault(); |
57 | 137 | targetElement.scrollIntoView({ behavior: 'smooth' }); |
58 | 138 | history.pushState(null, '', href); |
59 | 139 | } else { |
60 | | - // Target does not exist, go to homepage + anchor |
61 | 140 | e.preventDefault(); |
62 | 141 | window.location.href = '/' + href; |
63 | 142 | } |
64 | 143 | } |
65 | 144 | }); |
66 | 145 | }); |
| 146 | + |
| 147 | + // Mobile anchor links |
| 148 | + const mobileAnchors = document.querySelectorAll('.mobile-anchor'); |
| 149 | + mobileAnchors.forEach(link => { |
| 150 | + const href = link.getAttribute('href'); |
| 151 | + if (!href || !href.startsWith('#')) return; |
| 152 | + |
| 153 | + link.addEventListener('click', (e) => { |
| 154 | + const targetId = href.substring(1); |
| 155 | + const targetElement = document.getElementById(targetId); |
| 156 | + |
| 157 | + if (!isHomePage && targetElement) { |
| 158 | + e.preventDefault(); |
| 159 | + window.location.href = '/' + href; |
| 160 | + } else if (targetElement) { |
| 161 | + e.preventDefault(); |
| 162 | + targetElement.scrollIntoView({ behavior: 'smooth' }); |
| 163 | + } |
| 164 | + }); |
| 165 | + }); |
67 | 166 | } |
68 | 167 |
|
69 | 168 | // Run on load |
|
0 commit comments