From 492e53609bf3df6c9db23d4e05d77d449cafa545 Mon Sep 17 00:00:00 2001 From: yiqiu Date: Sat, 10 Jan 2026 18:02:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E8=8F=9C=E5=8D=95=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/common.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/common/common.js b/common/common.js index 9a2aab9..268d80a 100644 --- a/common/common.js +++ b/common/common.js @@ -144,20 +144,25 @@ $(function () { hoverTimer = setTimeout(() => { const $menu = $(".nav-cont .nav-cont-menu").eq(index); - if (!$menu.hasClass("nav-cont-empty")) { + // 检查菜单是否存在且不为空 + if ($menu.length > 0 && !$menu.hasClass("nav-cont-empty")) { // 1. 先让容器从0开始(防止闪烁) $(".nav-cont").css("height", "0px"); - // 2. 显示菜单(但容器高度为0,所以看不见) + // 2. 隐藏所有其他菜单 + $(".nav-cont .nav-cont-menu").css("display", "none"); + + // 3. 显示当前菜单(但容器高度为0,所以看不见) $menu.css("display", "block"); - // 3. 立即获取高度并展开(使用requestAnimationFrame确保渲染) + // 4. 立即获取高度并展开(使用requestAnimationFrame确保渲染) requestAnimationFrame(() => { const height = $menu.outerHeight(true); $(".nav-cont").css("height", height + "px"); }); + + showIndex = index; } - showIndex = index; }, 150); }, function () { @@ -168,12 +173,11 @@ $(function () { } leaveTimer = setTimeout(() => { - const index = $(".nav-menu .nav-item").index($(this)); // 先收起容器 $(".nav-cont").css("height", "0"); // 等动画完成后隐藏内容 setTimeout(() => { - $(".nav-cont .nav-cont-menu").eq(index).css("display", "none"); + $(".nav-cont .nav-cont-menu").css("display", "none"); }, 300); // 等待transition完成 }, 100); } @@ -188,9 +192,10 @@ $(function () { } const $menu = $(".nav-cont .nav-cont-menu").eq(showIndex); - $menu.css("display", "block"); - if (!$menu.hasClass("nav-cont-empty")) { + if ($menu.length > 0 && !$menu.hasClass("nav-cont-empty")) { + $menu.css("display", "block"); + requestAnimationFrame(() => { const height = $menu.outerHeight(true); $(".nav-cont").css("height", height + "px");