我正在尝试使用hoverintent 插件来替换以下 javascript 代码:
$('#top').on('mouseenter', '#nav', function(e){
$('#top ul').delay(100).slideDown(300);
$('#top').stop().animate({
height: 230
}, 400);
});
$('body').on('mouseleave', '#top', function(e){
$('#top ul').slideUp(300);
$('#top').stop().animate({
height: 97
}, 400);
});
我的html是:
<div id="main">
<div id="top">
<a href="#" class="logo"></a>
<ol id="nav">
<li><a href="#">Home</a></li>
<li>
<a href="#">Company</a>
<ul>
<li><a href="#">About us</a></li>
<li><a href="#">Management</a></li>
<li><a href="#">Careers</a></li>
</ul>
</li>
<li>
<a href="#">Products</a>
<ul>
<li><a href="#">Product 1</a></li>
<li><a href="#">Product 2</a></li>
<li><a href="#">Product 3</a></li>
</ul>
</li>
<li><a href="#">Contact Us</a></li>
</ol>
</div>
</div>
这是我的CSS:
html { background:#fff; font-family: Arial, Helvetica, sans-serif; }
#main { position: relative; width: 860px; margin: 0 auto; text-align: left; padding: 0 40px; }
#top { width: 860px; height: 97px; border-bottom: 1px solid #f0f1f0; padding-bottom: 30px; }
#top a.logo { display: block; float: left; width: 186px; height: 55px; margin-top: 40px; background: #ccc; }
#top a.logo:hover { background: #ddd; }
#top ol { position: absolute; top: 37px; right: 40px; display: block; overflow: visible; z-index: 10; }
#top ol li { display: inline-block; float: left; text-align: right; margin-left: 24px; padding-top: 20px; }
#top ol li a { display: block; font-family: "Arial Narrow", "Helvetica Narrow", sans-serif; font-size: 0.8em; color: #989f98; text-decoration: none; text-transform: uppercase; margin-bottom: 5px; }
#top ol li a.current,
#top ol li a:hover { color: #e9292f; }
#top ul { display: none; padding-bottom: 6px; max-width: 95px; border-top: 1px dotted #d1d1d1; }
#top ul li { display: block; float: none; margin-left: 0; padding-top: 3px; }
#top ul li a { font-size: 0.7em; font-family: Arial, Helvetica, sans-serif; text-transform: none; }
这是我要实现的目标的快速图表:
我想要的只是让用户将鼠标悬停在鼠标上,#nav
并且只有当他们将鼠标移出#top
(在我的图表中为灰色)时它才会消失。鉴于 hoverintent 网站上的示例,我不知道如何实现这一点:(
有人有任何指示吗?提前致谢!
- - - 编辑 - - -
通过执行以下操作使悬停意图达到一定程度:
var config = {
over: function(){
$('#top ul').delay(100).slideDown(300);
$('#top').stop().animate({
height: 230
}, 400);
},
timeout: 0,
out: function(){
$('#top ul').slideUp(300);
$('#top').stop().animate({
height: 97
}, 400);
}
};
$('#nav').hoverIntent(config);
现在,当我将鼠标移出而不是div时,问题就ul
消失了。关闭但没有雪茄:(#nav
#top