This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user