diff --git a/common/common.js b/common/common.js index 0ee410f..9a2aab9 100644 --- a/common/common.js +++ b/common/common.js @@ -133,7 +133,7 @@ $(function () { $(".nav-menu .nav-item").hover( function () { const index = $(".nav-menu .nav-item").index($(this)); - + // 清除离开定时器 if (leaveTimer) { clearTimeout(leaveTimer); @@ -142,15 +142,20 @@ $(function () { // 添加150ms延迟,防止误触 hoverTimer = setTimeout(() => { - $(".nav-cont .nav-cont-menu") - .eq(index) - .css("display", "block"); + const $menu = $(".nav-cont .nav-cont-menu").eq(index); - if ( - !$(".nav-cont .nav-cont-menu").eq(index).hasClass("nav-cont-empty") - ) { - const height = $(".nav-cont .nav-cont-menu").eq(index).outerHeight(true); - $(".nav-cont").css("height", height + "px"); + if (!$menu.hasClass("nav-cont-empty")) { + // 1. 先让容器从0开始(防止闪烁) + $(".nav-cont").css("height", "0px"); + + // 2. 显示菜单(但容器高度为0,所以看不见) + $menu.css("display", "block"); + + // 3. 立即获取高度并展开(使用requestAnimationFrame确保渲染) + requestAnimationFrame(() => { + const height = $menu.outerHeight(true); + $(".nav-cont").css("height", height + "px"); + }); } showIndex = index; }, 150); @@ -164,8 +169,12 @@ $(function () { leaveTimer = setTimeout(() => { const index = $(".nav-menu .nav-item").index($(this)); - $(".nav-cont .nav-cont-menu").eq(index).css("display", "none"); + // 先收起容器 $(".nav-cont").css("height", "0"); + // 等动画完成后隐藏内容 + setTimeout(() => { + $(".nav-cont .nav-cont-menu").eq(index).css("display", "none"); + }, 300); // 等待transition完成 }, 100); } ); @@ -178,25 +187,28 @@ $(function () { leaveTimer = null; } - $(".nav-cont .nav-cont-menu") - .eq(showIndex) - .css("display", "block"); - - if (!$(".nav-cont .nav-cont-menu").eq(showIndex).hasClass("nav-cont-empty")) { - const height = $(".nav-cont .nav-cont-menu").eq(showIndex).outerHeight(true); - $(".nav-cont").css("height", height + "px"); + const $menu = $(".nav-cont .nav-cont-menu").eq(showIndex); + $menu.css("display", "block"); + + if (!$menu.hasClass("nav-cont-empty")) { + requestAnimationFrame(() => { + const height = $menu.outerHeight(true); + $(".nav-cont").css("height", height + "px"); + }); } }, function () { leaveTimer = setTimeout(() => { - $(".nav-cont .nav-cont-menu") - .eq(showIndex) - .css("display", "none"); + // 先收起容器 $(".nav-cont").css("height", "0"); + // 等动画完成后隐藏内容 + setTimeout(() => { + $(".nav-cont .nav-cont-menu").eq(showIndex).css("display", "none"); + }, 300); }, 100); } ); - + if (localStorage.jwt) { if (sessionStorage.accountInfo) { const obj = JSON.parse(sessionStorage.accountInfo); diff --git a/css/nav-mega-menu.css b/css/nav-mega-menu.css index c167335..0fe2263 100644 --- a/css/nav-mega-menu.css +++ b/css/nav-mega-menu.css @@ -11,8 +11,9 @@ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); border-top: 1px solid rgba(56, 189, 248, 0.15); z-index: 1000; - overflow: visible; + overflow: hidden; transition: height 0.3s ease-out; + height: 0; } /* Mega Menu 两栏布局 */ @@ -27,6 +28,7 @@ margin: 0 auto; height: 100%; min-height: 400px; + padding: 0; } /* 左侧二级菜单栏 - 深色背景 */ @@ -86,7 +88,7 @@ /* 右侧三级菜单区域 - 深色背景 */ .nav-right-content { flex: 1; - padding: 24px 32px; + padding: 16px 24px; background: rgba(15, 23, 42, 0.6); overflow-y: auto; max-height: none;