Skip to content

Commit 9e3a1a5

Browse files
committed
Fix: update menu@mobile style
1 parent b6f1cca commit 9e3a1a5

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

docs/css/responsive.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ footer {
244244
width: 100%;
245245
text-align: center;
246246
margin: 0;
247+
position: relative; /* 添加相对定位 */
247248
}
248249

249250
.nav-link {
@@ -258,6 +259,26 @@ footer {
258259
text-transform: uppercase;
259260
letter-spacing: 1px;
260261
font-weight: 500;
262+
position: relative; /* 添加相对定位用于伪元素 */
263+
}
264+
265+
/* 移动端导航链接的底部横线 */
266+
.nav-link::after {
267+
content: '';
268+
position: absolute;
269+
bottom: 8px; /* 距离底部的距离 */
270+
left: 50%; /* 从中心开始 */
271+
transform: translateX(-50%); /* 居中对齐 */
272+
width: 0; /* 初始宽度为0 */
273+
height: 2px;
274+
background: linear-gradient(90deg, var(--neon-blue, #00f5ff), var(--neon-purple, #b224ef));
275+
transition: width 0.3s ease;
276+
border-radius: 1px;
277+
}
278+
279+
.nav-link:hover::after,
280+
.nav-link.active::after {
281+
width: calc(100% - 40px); /* 100%宽度减去左右padding */
261282
}
262283

263284
.nav-link:hover,
@@ -268,6 +289,18 @@ footer {
268289
transform: translateX(10px);
269290
}
270291

292+
/* 如果你想要横线完全覆盖整个链接宽度,使用这个版本 */
293+
.nav-link.full-width::after {
294+
width: 100%;
295+
left: 0;
296+
transform: none;
297+
}
298+
299+
.nav-link.full-width:hover::after,
300+
.nav-link.full-width.active::after {
301+
width: 100%;
302+
}
303+
271304
/* 汉堡菜单动画 */
272305
.hamburger.active .bar:nth-child(1) {
273306
transform: translateY(7px) rotate(45deg);
@@ -373,6 +406,18 @@ footer {
373406
overflow: auto !important;
374407
height: auto !important;
375408
}
409+
410+
.nav-link::after {
411+
bottom: -2px !important;
412+
left: 50% !important;
413+
transform: translateX(-50%) !important;
414+
width: 0 !important;
415+
}
416+
417+
.nav-link:hover::after,
418+
.nav-link.active::after {
419+
width: 100% !important;
420+
}
376421
}
377422

378423
/* 导入关于我们的样式 */

docs/js/responsive.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,46 @@ document.addEventListener('DOMContentLoaded', function() {
239239
}
240240
});
241241
}
242+
243+
// 移动端导航链接样式优化
244+
function optimizeMobileNavLinks() {
245+
const navLinks = document.querySelectorAll('.nav-link');
246+
247+
if (window.innerWidth <= 768) {
248+
navLinks.forEach(link => {
249+
// 添加移动端特定的类
250+
link.classList.add('mobile-nav-link');
251+
252+
// 鼠标进入事件
253+
link.addEventListener('mouseenter', function() {
254+
this.style.setProperty('--underline-width', '100%');
255+
});
256+
257+
// 鼠标离开事件(仅对非活动链接)
258+
link.addEventListener('mouseleave', function() {
259+
if (!this.classList.contains('active')) {
260+
this.style.setProperty('--underline-width', '0%');
261+
}
262+
});
263+
});
264+
} else {
265+
// 桌面端移除移动端类
266+
navLinks.forEach(link => {
267+
link.classList.remove('mobile-nav-link');
268+
link.style.removeProperty('--underline-width');
269+
});
270+
}
271+
}
272+
273+
// 初始化
274+
optimizeMobileNavLinks();
275+
276+
// 窗口大小改变时重新优化
277+
window.addEventListener('resize', function() {
278+
optimizeMobileNavLinks();
279+
280+
if (window.innerWidth > 768) {
281+
closeMenu();
282+
}
283+
});
242284
});

0 commit comments

Comments
 (0)