jQuery mouseoverIntent 插件在父级悬停时显示/隐藏 div,但悬停时保持显示
我有一个按钮,当鼠标悬停在其上方时,会在其正下方显示一个 div。当悬停(鼠标悬停)时,div 消失。
这一切都运行良好,但现在我需要将 div 保留在按钮下方,显示用户是否将鼠标悬停在该 div 上(以与 div 内的内容进行交互)。
目前这是不可能的,因为当您将鼠标悬停在触发 div 显示的按钮之外时,div 会立即消失。
我使用 hoverIntent jQuery 插件来完成此任务。
// This is the button that when hovered
// triggers the div below it to show
$('#hoverMeToShowHideDiv').hoverIntent(function () {
$("#displayDiv").stop().slideDown('slow');
},
function () {
// I don't want the div to hide if user hovers over it
$("#displayDiv").stop().slideUp('slow');
});
HTML:
<div id="hoverMeToShowHideDiv"> // some stuff </div>
<div id="displayDiv">
// some other stuff that I want to
// keep showing if users hover over it
</div>
I have a button that when hovered over (mouseover) displays a div right below it. When hovered away (mouseout), the div disappears.
This all works well and nicely, but now I need to keep the div below the button showing if user hovers over that div (to interact with the content inside the div).
Right now this is not possible since the div will disappear immediately after you hover away from the button that triggers the div to display.
I'm using the hoverIntent jQuery Plugin to accomplish this.
// This is the button that when hovered
// triggers the div below it to show
$('#hoverMeToShowHideDiv').hoverIntent(function () {
$("#displayDiv").stop().slideDown('slow');
},
function () {
// I don't want the div to hide if user hovers over it
$("#displayDiv").stop().slideUp('slow');
});
The HTML:
<div id="hoverMeToShowHideDiv"> // some stuff </div>
<div id="displayDiv">
// some other stuff that I want to
// keep showing if users hover over it
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将另一个 div
#wrapperDiv
放在按钮和#displayDiv
周围,并将悬停意图附加到#wrapperDiv
而不是按钮:HTML:
Stick another div
#wrapperDiv
around both the button and the#displayDiv
and attach hoverIntent to#wrapperDiv
rather than the button:HTML: