我创建了一个下拉菜单,其中每个主链接都有一个附加事件mouseenter
,mouseleave
首先检查是否有与链接关联的子导航列表,然后将菜单滑动到可见性。如果您输入链接 1 并将下拉菜单滑入然后滑出,则此方法可以正常工作,但是如果您输入链接 1,然后将鼠标悬停在链接 2 上,则slideUp()
一致性已经消失,理想情况下,我想确保活动菜单在新mouseenter
代码之前已关闭再次运行。谁能建议我如何实现这一目标?
小提琴链接:http: //jsfiddle.net/f3ZpN/1/
JS
var mainNav = $('.main-nav'),
topLevelLinks = mainNav.children('li'),
subNav = $('.sub-nav-panel'),
subNavPanel,
isActive = false,
inner,
innerLink;
topLevelLinks.on({
mouseenter: function () {
var el = $(this);
if (el.children('.sub-nav').length > 0) {
inner = el.children('.sub-nav');
subNav.stop(true, true).slideDown(function () {
inner.fadeIn();
});
}
},
mouseleave: function () {
//make sure this finishes before mouseenter is run again?
inner.fadeOut(function() {
subNav.slideUp();
});
}
});