refactor: 导航下拉菜单重构为方案 C 混合型
All checks were successful
continuous-integration/drone/push Build is passing

- public/header.html: 去掉左右分栏,改为二级分组标题 + 三级国旗链接网格
- css/nav-mega-menu.css: 居中收窄面板(720px),分组标题+网格布局
- js/nav-third-level.js: 清空旧的面板切换脚本(不再需要)
- 下拉面板不再全宽铺开,视觉更精致紧凑
This commit is contained in:
yiqiu
2026-03-18 18:03:27 +08:00
parent cc141973a5
commit f3d3a2954f
3 changed files with 138 additions and 306 deletions

View File

@@ -1,146 +1,105 @@
/* ============================================================ /* ============================================================
顶部导航下拉菜单样式 - akile.io 深色毛玻璃风格 导航下拉菜单 — 方案 C 混合型
二级分组标题 + 三级国旗链接网格,居中收窄面板
============================================================ */ ============================================================ */
/* 下拉容器 */ /* ── 下拉外层容器 ── */
.nav-cont { .nav-cont {
position: absolute; position: absolute;
top: 100%; top: 100%;
left: 0; left: 0;
width: 100%; width: 100%;
background: rgba(14, 16, 26, 0.98);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border-top: 1px solid rgba(255, 255, 255, 0.06);
box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6);
z-index: 1000; z-index: 1000;
overflow: hidden; overflow: hidden;
transition: height 0.25s ease-out; transition: height 0.25s ease-out;
height: 0; height: 0;
/* 不设背景,由 inner 负责 */
} }
/* Mega Menu 容器 */ /* ── 下拉内层 —— 居中收窄面板 ── */
.nav-cont-menu.mega-menu { .nav-dropdown-inner {
display: none;
height: 100%;
}
/* inner 布局 */
.nav-content {
display: flex; display: flex;
max-width: 1400px; justify-content: center;
margin: 0 auto;
height: 100%;
min-height: 320px;
padding: 0; padding: 0;
} }
/* ── 左侧二级菜单栏 ── */ /* ── 每个一级导航对应的菜单面板 ── */
.nav-left-sidebar { .nav-cont-menu {
width: 220px; display: none;
flex-shrink: 0; width: 100%;
background: rgba(255, 255, 255, 0.03); max-width: 720px;
border-right: 1px solid rgba(255, 255, 255, 0.06); margin: 0 auto;
padding: 16px 8px; background: rgba(14, 16, 26, 0.98);
overflow-y: auto; backdrop-filter: blur(24px);
-webkit-backdrop-filter: blur(24px);
border: 1px solid rgba(255, 255, 255, 0.08);
border-top: none;
border-radius: 0 0 14px 14px;
box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55),
0 0 0 1px rgba(255, 255, 255, 0.04) inset;
padding: 20px 0 12px;
} }
/* 二级分类项 */ .nav-cont-menu.nav-cont-empty {
.nav-category-item { display: none !important;
}
/* ── 分组容器 (方案 C 核心) ── */
.nav-groups {
padding: 0 24px;
}
.nav-group {
margin-bottom: 8px;
}
.nav-group:last-child {
margin-bottom: 0;
}
/* ── 二级分组标题行 ── */
.nav-group-title {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 8px;
padding: 11px 14px; padding: 8px 8px 6px;
color: rgba(203, 213, 225, 0.75); font-size: 12px;
font-size: 14px; font-weight: 600;
font-weight: 500; color: rgba(148, 163, 184, 0.7);
border-radius: 8px; text-transform: uppercase;
cursor: pointer; letter-spacing: 0.06em;
transition: background 0.15s ease, color 0.15s ease; border-bottom: 1px solid rgba(255, 255, 255, 0.05);
margin-bottom: 6px;
user-select: none; user-select: none;
} }
.nav-category-item:hover, .nav-group-icon {
.nav-category-item.active { width: 18px;
background: rgba(59, 130, 246, 0.12); height: 18px;
color: #93C5FD;
}
.nav-category-item .category-icon {
width: 20px;
height: 20px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.nav-category-item .category-icon img {
width: 100%;
height: 100%;
object-fit: contain; object-fit: contain;
opacity: 0.7;
} }
.nav-category-name { .nav-group-desc {
font-weight: 500; font-weight: 400;
font-size: 11px;
color: rgba(148, 163, 184, 0.45);
letter-spacing: 0;
text-transform: none;
} }
.nav-category-desc { /* ── 三级链接网格 ── */
font-size: 12px; .nav-group-grid {
color: rgba(148, 163, 184, 0.6);
margin-top: 2px;
display: block;
}
/* ── 右侧三级菜单区域 ── */
.nav-right-content {
flex: 1;
padding: 20px 28px;
overflow-y: auto;
}
/* 三级菜单面板 */
.nav-third-panel {
display: none;
}
.nav-third-panel.active {
display: block;
animation: navPanelFadeIn 0.2s ease;
}
/* 三级菜单标题 */
.nav-third-title {
font-size: 13px;
font-weight: 600;
color: rgba(148, 163, 184, 0.6);
text-transform: uppercase;
letter-spacing: 0.08em;
margin-bottom: 12px;
padding-bottom: 10px;
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
/* 三级菜单网格 */
.nav-third-grid {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
gap: 4px 8px; gap: 2px;
} }
/* 三级菜单项容器 */ /* ── 三级链接项 ── */
.nav-cont-menu .nav-third-item { .nav-grid-link {
margin: 0;
padding: 0;
}
/* 三级菜单链接 - akile 风格:纯行 hover无卡片 */
.nav-cont-menu .nav-third-grid .nav-third-link,
.nav-third-panel .nav-third-link {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
width: 100%;
padding: 10px 12px; padding: 10px 12px;
border-radius: 8px; border-radius: 8px;
color: rgba(226, 232, 240, 0.85); color: rgba(226, 232, 240, 0.85);
@@ -148,23 +107,13 @@
font-weight: 500; font-weight: 500;
text-decoration: none; text-decoration: none;
transition: background 0.15s ease, color 0.15s ease; transition: background 0.15s ease, color 0.15s ease;
box-sizing: border-box;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
/* 无边框、无卡片背景 */
background: transparent;
border: none;
} }
.nav-cont-menu .nav-third-grid .nav-third-link::before, .nav-grid-link:hover {
.nav-third-panel .nav-third-link::before { background: rgba(255, 255, 255, 0.07);
content: none; /* 移除旧的 箭头前缀 */
}
.nav-cont-menu .nav-third-grid .nav-third-link:hover,
.nav-third-panel .nav-third-link:hover {
background: rgba(255, 255, 255, 0.06);
color: #fff; color: #fff;
} }
@@ -173,48 +122,42 @@
width: 22px; width: 22px;
height: 16px; height: 16px;
flex-shrink: 0; flex-shrink: 0;
vertical-align: middle;
object-fit: cover; object-fit: cover;
border-radius: 3px; border-radius: 3px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
} }
/* ── 只有二级菜单时的横向网格(无三级) ── */ /* ── 纯二级:简单网格 ── */
.nav-simple-grid { .nav-simple-grid {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 4px 8px; gap: 2px;
padding: 20px 28px; padding: 4px 24px 8px;
width: 100%;
max-width: 1400px;
margin: 0 auto;
box-sizing: border-box;
} }
.nav-simple-grid .nav-simple-item { .nav-simple-item {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 12px; gap: 12px;
padding: 11px 14px; padding: 10px 12px;
border-radius: 8px; border-radius: 8px;
color: rgba(226, 232, 240, 0.85); color: rgba(226, 232, 240, 0.85);
text-decoration: none;
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
text-decoration: none;
transition: background 0.15s ease, color 0.15s ease; transition: background 0.15s ease, color 0.15s ease;
/* 无卡片边框背景 */
background: transparent; background: transparent;
border: none; border: none;
} }
.nav-simple-grid .nav-simple-item:hover { .nav-simple-item:hover {
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.07);
color: #fff; color: #fff;
} }
.nav-simple-icon { .nav-simple-icon {
width: 28px; width: 24px;
height: 28px; height: 24px;
flex-shrink: 0; flex-shrink: 0;
} }
@@ -228,76 +171,26 @@
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
color: inherit; color: inherit;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
} }
.nav-simple-desc { .nav-simple-desc {
font-size: 12px; font-size: 12px;
color: rgba(148, 163, 184, 0.65); color: rgba(148, 163, 184, 0.6);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 2px; margin-top: 2px;
} }
/* ── 菜单底部「更多」区域 ── */ /* ── 菜单 ── */
.nav-menu-footer {
border-top: 1px solid rgba(255, 255, 255, 0.06);
padding: 12px 28px;
}
.nav-menu-footer a {
font-size: 13px;
color: rgba(148, 163, 184, 0.7);
text-decoration: none;
transition: color 0.15s ease;
}
.nav-menu-footer a:hover {
color: #93C5FD;
}
/* ── 空菜单占位 ── */
.nav-cont-menu.nav-cont-empty { .nav-cont-menu.nav-cont-empty {
display: none; display: none;
} }
/* ── 动画 ── */
@keyframes navPanelFadeIn {
from {
opacity: 0;
transform: translateX(8px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
/* ── 响应式 ── */ /* ── 响应式 ── */
@media (max-width: 768px) { @media (max-width: 768px) {
.nav-cont { .nav-cont {
display: none !important; display: none !important;
} }
.nav-content { .nav-group-grid {
flex-direction: column;
min-height: auto;
}
.nav-left-sidebar {
width: 100%;
border-right: none;
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.nav-right-content {
padding: 16px;
}
.nav-third-grid {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
} }

View File

@@ -1,50 +1,3 @@
// 三级导航菜单交互脚本 // nav-third-level.js
(function () { // 方案 C 混合型:三级菜单直接平铺展示,不需要面板切换逻辑
'use strict'; // 保留此文件以避免 header.html 中的 <script src> 引用报 404
// 初始化三级导航
function initThirdLevelNav() {
const navContMenus = document.querySelectorAll('.nav-cont-menu.mega-menu');
navContMenus.forEach(menu => {
const categoryItems = menu.querySelectorAll('.nav-category-item');
const thirdPanels = menu.querySelectorAll('.nav-third-panel');
if (categoryItems.length === 0 || thirdPanels.length === 0) {
return; // 没有三级菜单
}
// 默认激活第一个
if (categoryItems[0]) {
categoryItems[0].classList.add('active');
}
if (thirdPanels[0]) {
thirdPanels[0].classList.add('active');
}
// 绑定hover事件
categoryItems.forEach((item, index) => {
item.addEventListener('mouseenter', function () {
// 移除所有active状态
categoryItems.forEach(cat => cat.classList.remove('active'));
thirdPanels.forEach(panel => panel.classList.remove('active'));
// 激活当前
this.classList.add('active');
const categoryIndex = this.getAttribute('data-category-index');
const targetPanel = menu.querySelector(`.nav-third-panel[data-panel-index="${categoryIndex}"]`);
if (targetPanel) {
targetPanel.classList.add('active');
}
});
});
});
}
// DOM加载完成后初始化
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initThirdLevelNav);
} else {
initThirdLevelNav();
}
})();

View File

@@ -60,90 +60,76 @@
</nav> </nav>
<div class="nav-cont"> <div class="nav-cont">
<div class="section-content"> <div class="nav-dropdown-inner">
{if isset($data.header_nav) && !empty($data.header_nav)} {if isset($data.header_nav) && !empty($data.header_nav)}
{foreach $data.header_nav as $k=>$item} {foreach $data.header_nav as $k=>$item}
{if isset($item.children) && !empty($item.children)} {if isset($item.children) && !empty($item.children)}
<div class="nav-cont-menu mega-menu animated"> <div class="nav-cont-menu">
<div class="nav-content">
{php} {php}
// 检查是否有包含三级菜单的二级项 $hasThirdLevel = false;
$hasThirdLevel = false; foreach ($item['children'] as $child) {
foreach ($item['children'] as $child) {
if (isset($child['children']) && !empty($child['children'])) { if (isset($child['children']) && !empty($child['children'])) {
$hasThirdLevel = true; $hasThirdLevel = true;
break; break;
} }
} }
{/php} {/php}
{if $hasThirdLevel} {if $hasThirdLevel}
<!-- 左侧二级菜单栏 --> <!-- 方案 C二级分组标题 + 三级国旗链接网格 -->
<div class="nav-left-sidebar"> <div class="nav-groups">
{foreach $item.children as $childIndex=>$child} {foreach $item.children as $childIndex=>$child}
{if isset($child.children) && !empty($child.children)} {if isset($child.children) && !empty($child.children)}
<div class="nav-category-item" data-category-index="{$childIndex}"> <div class="nav-group">
<div class="nav-group-title">
{if !empty($child.icon)} {if !empty($child.icon)}
<span class="category-icon"> <img src="{$child.icon}" alt="{$child.name}" class="nav-group-icon">
<img src="{$child.icon}" alt="{$child.name}">
</span>
{/if} {/if}
<span class="nav-category-name">{$child.name}</span> <span>{$child.name}</span>
{if !empty($child.description)} {if !empty($child.description)}
<span class="nav-category-desc">{$child.description}</span> <span class="nav-group-desc">{$child.description}</span>
{/if} {/if}
</div> </div>
{/if} <div class="nav-group-grid">
{/foreach} {foreach $child.children as $grandchild}
</div> <a href="{if !empty($grandchild.file_address)}{$grandchild.file_address}{else/}javascript:;{/if}"
class="nav-grid-link" {if !empty($grandchild.blank)}target="_blank" {/if}
<!-- 右侧三级菜单区域 --> title="{$grandchild.name}{if !empty($grandchild.description)} - {$grandchild.description}{/if}">
<div class="nav-right-content"> {if !empty($grandchild.country_code)}
{foreach $item.children as $childIndex=>$child} <img src="/web/BlackFruit-web/assets/country/{$grandchild.country_code}.png"
{if isset($child.children) && !empty($child.children)} alt="{$grandchild.country_code}" class="country-flag" onerror="this.style.display='none'">
<div class="nav-third-panel" data-panel-index="{$childIndex}">
<div class="nav-third-title">{$child.name}</div>
<div class="nav-third-grid">
{foreach $child.children as $grandchild}
<div class="nav-third-item">
<a href="{if !empty($grandchild.file_address)}{$grandchild.file_address}{else/}javascript:;{/if}"
class="nav-third-link" {if !empty($grandchild.blank)}target="_blank" {/if}
title="{$grandchild.name}{if !empty($grandchild.description)} - {$grandchild.description}{/if}">
{if !empty($grandchild.country_code)}
<img src="/web/BlackFruit-web/assets/country/{$grandchild.country_code}.png"
alt="{$grandchild.country_code}" class="country-flag" onerror="this.style.display='none'">
{/if}
{$grandchild.name}
</a>
</div>
{/foreach}
</div>
</div>
{/if}
{/foreach}
</div>
{else}
<!-- 无三级菜单,使用横向网格布局 -->
<div class="nav-simple-grid">
{foreach $item.children as $child}
<a href="{if !empty($child.file_address)}{$child.file_address}{else/}javascript:;{/if}"
class="nav-simple-item" {if !empty($child.blank)}target="_blank" {/if}>
{if !empty($child.icon)}
<div class="nav-simple-icon">
<img src="{$child.icon}" alt="{$child.name}">
</div>
{/if}
<div class="nav-simple-info">
<div class="nav-simple-title">{$child.name}</div>
{if !empty($child.description)}
<div class="nav-simple-desc">{$child.description}</div>
{/if} {/if}
</div> {$grandchild.name}
</a> </a>
{/foreach} {/foreach}
</div>
</div> </div>
{/if} {/if}
{/foreach}
</div> </div>
{else}
<!-- 纯二级:简单网格 -->
<div class="nav-simple-grid">
{foreach $item.children as $child}
<a href="{if !empty($child.file_address)}{$child.file_address}{else/}javascript:;{/if}"
class="nav-simple-item" {if !empty($child.blank)}target="_blank" {/if}>
{if !empty($child.icon)}
<div class="nav-simple-icon">
<img src="{$child.icon}" alt="{$child.name}">
</div>
{/if}
<div class="nav-simple-info">
<div class="nav-simple-title">{$child.name}</div>
{if !empty($child.description)}
<div class="nav-simple-desc">{$child.description}</div>
{/if}
</div>
</a>
{/foreach}
</div>
{/if}
</div> </div>
{else /} {else /}
<div class="nav-cont-menu nav-cont-empty"></div> <div class="nav-cont-menu nav-cont-empty"></div>