使用 setTimeout 的 Jquery mouseover mouseout 菜单
有人可以帮我写这个简单的代码吗?我仍然是 js 新手,我不知道我做错了什么。基本上我正在尝试制作一个鼠标悬停菜单。
function showQuickLinks() {
//show the menu
}
function hideQuickLinks() {
//hides the menu
}
//button mouseover
$("#quick-links-dd").mouseover(function() {
showQuickLinks();
});
var mnuTimeout;
//clears timeout when it rolls over the button
$("#quick-links-dd").mouseover(function () {
clearTimeout(mnuTimeout);
})
//$("#quick-links) - quick links container
//hides the menu when the mouse is not over the container
$("#quick-links").mouseout(function () {
mnuTimeout = setTimeout("hideQuickLinks()",1000);
});
鼠标悬停可以工作,但当鼠标位于链接容器之外时,它不会执行代码。
Can someone help me with this simple code.. I'm still a noob on js and I don't know what im doing wrong. Basically Im trying to make a mouseover menu.
function showQuickLinks() {
//show the menu
}
function hideQuickLinks() {
//hides the menu
}
//button mouseover
$("#quick-links-dd").mouseover(function() {
showQuickLinks();
});
var mnuTimeout;
//clears timeout when it rolls over the button
$("#quick-links-dd").mouseover(function () {
clearTimeout(mnuTimeout);
})
//$("#quick-links) - quick links container
//hides the menu when the mouse is not over the container
$("#quick-links").mouseout(function () {
mnuTimeout = setTimeout("hideQuickLinks()",1000);
});
The mouse over works but it doesn't execute the code when the mouse is outside the link container.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是不是少了一个“?
Are you missing a " ?
我遇到过间歇性丢失 onmouseout 事件的问题。我最终的解决方案是将鼠标悬停事件添加到周围的元素,并让它们也取消弹出窗口。
I've had intermittent issues with lost onmouseout events. My eventual solution was to add mouseover events to surrounding elements, and have them also cancel the popup.