用于非嵌套菜单内容的 JQuery HoverIntent
我正在使用 JQuery HoverIntent 创建菜单。
这是我的 HTML 代码的基本结构:
<ul>
<li><a href="#" class="current">Home</a></li>
<li id="sh-zone-menu-sub-services" class="submenu"><a href="#">Services</a></li>
<li id="sh-zone-menu-sub-support" class="submenu"><a href="#">Support</a></li>
<li id="sh-zone-menu-sub-contact" class="submenu"><a href="#">Contact</a></li>
<li><a href="#">About Us</a></li>
</ul>
<div id="sh-zone-menu-sub-services-target" class="submenu-content">Services Content</div>
<div id="sh-zone-menu-sub-support-target" class="submenu-content">Support Content</div>
<div id="sh-zone-menu-sub-contact-target" class="submenu-content">Contact Content</div>
这是 JQuery 代码:
var $_ = jQuery;
$_(document).ready(function(){
function showSubMenu()
{
var source_id = $_(this).attr("id");
$_(this).addClass("showsubmenu");
$_("#"+source_id+"-target").show();
}
function hideSubMenu()
{
var source_id = $_(this).attr("id");
$_(this).removeClass("showsubmenu");
$_("#"+source_id+"-target").hide();
}
var subMenuConfig =
{
interval: 100,
sensitivity: 4,
over: showSubMenu,
timeout: 300,
out: hideSubMenu
};
$_("ul li.submenu").hoverIntent(subMenuConfig);
});
一切正常,但是当菜单内容显示并且我尝试将鼠标悬停在它上面时,它消失了。
按照之前配置 HTML 代码的方式,子菜单内容 DIV 嵌套在 LI 标记内,这可以正常工作,即菜单链接和内容悬停时。然而,我在 IE 定位方面遇到了问题(因为菜单内容占据了页面的很大一部分),所以我需要将它们从 LI 标签中删除。
我现在的方式对于 IE 来说可以正常工作(CSS 位置明智),但是悬停意图不起作用。
当我的菜单内容未嵌套在 LI 标签内时,有没有办法使用hoverIntent?!
谢谢。
I'm using JQuery HoverIntent to create a menu.
Here is the basic structure of my HTML code:
<ul>
<li><a href="#" class="current">Home</a></li>
<li id="sh-zone-menu-sub-services" class="submenu"><a href="#">Services</a></li>
<li id="sh-zone-menu-sub-support" class="submenu"><a href="#">Support</a></li>
<li id="sh-zone-menu-sub-contact" class="submenu"><a href="#">Contact</a></li>
<li><a href="#">About Us</a></li>
</ul>
<div id="sh-zone-menu-sub-services-target" class="submenu-content">Services Content</div>
<div id="sh-zone-menu-sub-support-target" class="submenu-content">Support Content</div>
<div id="sh-zone-menu-sub-contact-target" class="submenu-content">Contact Content</div>
And here's the JQuery Code:
var $_ = jQuery;
$_(document).ready(function(){
function showSubMenu()
{
var source_id = $_(this).attr("id");
$_(this).addClass("showsubmenu");
$_("#"+source_id+"-target").show();
}
function hideSubMenu()
{
var source_id = $_(this).attr("id");
$_(this).removeClass("showsubmenu");
$_("#"+source_id+"-target").hide();
}
var subMenuConfig =
{
interval: 100,
sensitivity: 4,
over: showSubMenu,
timeout: 300,
out: hideSubMenu
};
$_("ul li.submenu").hoverIntent(subMenuConfig);
});
Everything works ok, but when the menu content is revealed and I try to hover over it, it disappears.
The way the HTML code was configured previously, the submenu-content DIVs were nested within the LI tags, and this worked ok i.e. with hover of menu link and content. However, I was having issues with positioning for IE (because the menu content spans a large portion of the page), so I needed to take them out of LI tags.
The way I have it now works ok for IE (CSS position-wise), but hoverIntent is not working.
Is there a way to use hoverIntent when my menu content is not nested within the LI tags?!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道您不久前发布了这个问题,并且我对hoverIntent插件的经验有限,但这是我通过查看代码所知道的。 mouseenter 和 mouseleave 事件绑定到您绑定的hoverIntent 对象。绑定到你的对象的hoverIntent中的代码是:
因此,如果你保留一个ul并绑定到li元素,就像这样:
弹出窗口发生后(显示来自ul的更多元素),它不会触发 mouseleave 事件您将鼠标悬停在弹出窗口上,因为弹出窗口中的所有元素都是 ul 的子元素。
所以...如果你说...一个div包装器,里面有一个div作为悬停触发器,你只想用正确的语法绑定hoverIntent并且它工作正常(弹出窗口中的所有内容都是悬停的子级) element):
我正在寻找类似的东西并不断遇到这个问题。我以为我会回答它。
I know you posted this question a while ago and I have limited experience with the hoverIntent plugin, but here's what I know from looking at the code. The mouseenter and mouseleave events are bound to the object you bind hoverIntent to. The code in hoverIntent that binds to your object is:
So if you lave a ul and you bind to the li elements, something like this:
After the popup happens (displaying more elements from the ul) it doesn't fire the mouseleave event when you hover over the popup, because all of the elements in the popup are children of the ul.
So... if you have say... a div wrapper with a div inside it as the the hover trigger, you want to just bind hoverIntent with the right syntax and it works fine (everything in the popup is a child of the hovered element):
I was searching for something similar and kept coming across this question. Thought I would answer it.