gpt4 book ai didi

jQuery 悬停菜单 - 当鼠标悬停在子菜单上时 - 菜单消失

转载 作者:行者123 更新时间:2023-12-01 04:32:34 24 4
gpt4 key购买 nike

所以我创建了一个简单的小悬停,它使用链接中的类来显示下面的 div。

显示/隐藏工作正常,但我不知道如何设置它,这样如果鼠标位于 div 上,它就不会隐藏。我尝试使用 (this) 和 .hover,但没有成功。

这是我的代码:

$(document).ready(function()
{

// hide all dropdown
$("#dropdown1").hide();

//hover show dropdown

$(".menu-level-one").hover(
function () {
$("#dropdown1").show();
},
function () {
var postTimer1 = setTimeout(function(){ $("#dropdown1").hide(); }, 1000);
}
);
});

最佳答案

您可以使用clearTimeout(postTimer1)来停止计时器的执行。因此,如果用户将鼠标悬停在 #dropdown1 上,则清除计时器。

也许是这样的:

$(document).ready(function() {
var hideTimer = null
var dropdown = $("#dropdown1", this)
var menu = $(".menu-level-one", this)

dropdown.hide();

$([dropdown[0], menu[0]]).hover(
function() {
if (hideDropdownTimer)
clearTimeout(hideDropdownTimer);

dropdown.show();
},
function() {
if (hideDropdownTimer)
clearTimeout(hideDropdownTimer);

hideDropdownTimer = setTimeout(function() {
dropdown.hide()
}, 300)
}
)
})

关于jQuery 悬停菜单 - 当鼠标悬停在子菜单上时 - 菜单消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/419218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com