一旦进入我的菜单项,我隐藏的div会很好地滚下来然后如果你离开就会后退。问题是如果你已经在容器周围进行鼠标混合然后重新进入菜单项顶部,不幸的是重新启动并再次向下滑动隐藏容器:
所以我正在尝试做的是测试项目是否已经可见,如果只是继续显示容器。
关闭,因为我可以达到这个目的:
非常感谢任何帮助。
答案 0 :(得分:0)
这有效:
HTML:
<div id="container">
<div id="header">
<div id="boundary"></div>
<div id="menu">
<div id="about">
<div id="dd_about"></div>
</div>
</div>
</div>
</div>
javascript
var menustate = "hidden";
$('#about').bind('mouseenter', function() {
if (menustate == "hidden")
{
$('#dd_about').slideDown('fast');
menustate = "shown";
}
});
$('#about').bind('mouseleave', function () {
$('#dd_about').slideUp('fast');
menustate = "hidden";
});
CSS
#container {
width:500px;
margin:0 auto;
position:relative;
}
#header {
width:100%;
height:50px;
background:blue;
position:relative;
}
#boundary {
width:320px;
height:60px;
bottom:0;
right:0;
position:absolute;
background:purple;
}
#menu {
width:100px;
height:40px;
position:absolute;
right:10px;
top:10px;
}
#about {
width:100px;
height:40px;
float:left;
background:yellow;
}
#dd_about {
top : 40px;
left : 0px;
width:100px;
height:200px;
position:absolute;
background:red;
display:none;
}
#dd_about {right:10px}
就像这样:
使用此javascript
$('#about').bind('mouseenter', function() {
$('#dd_about').slideDown('fast');
});
$('#about').bind('mouseleave', function () {
$('#dd_about').slideUp('fast');
});
答案 1 :(得分:0)
要解决设置方式,请在此处查看jsfiddle。如果您想要主菜单中包含的dropdwon菜单,Hogan也给了您一个很好的答案。否则,我只是在stop(true, true)
上添加了#dd_about
调用,以停止播放动画。
答案 2 :(得分:0)
以下是工作演示http://jsfiddle.net/NAyWQ/21/
此示例使用标志变量来检查当前悬停状态
var hover = false;
$('#about').bind('mouseenter', function() {
hover = true;
$('#dd_about').slideDown('fast');
});
$('#boundary').bind('mouseenter', function () {
hover = false;
$('#dd_about').slideUp('fast');
});
$('#dd_about').bind('mouseleave', function () {
hover = false;
setTimeout(function() {
if (hover) return false;
$('#dd_about').slideUp('fast');
}, 50);
});