【发布时间】:2015-01-09 15:43:49
【问题描述】:
我们的想法是制作一个下拉菜单,首先所有菜单项都堆叠在顶部,悬停时它们会向下动画。
我通过将 line-height 设为 0 来做到这一点。悬停时将 lineHeight 设置为 35px。
问题是这也会将第一行向下移动,这有时会将鼠标定位到文本之外并使其再次跳起来。
我尝试将第一个项目留在动画之外,但这会导致重叠。
而且在搬进搬出几次之后,我停止工作一秒钟,我真的不知道为什么。
有人有解决办法吗?
我的 Javascript 和 jQuery 技能有限,所以我尝试用我知道的东西来创造。
第一次尝试
HTML
<h2>
<a>project one <br></a>
<a>number two <br></a>
<a>this would be project three<br></a>
<a>and number four <br></a>
</h2>
CSS
h2 {
left:10px;
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-size:36px;
font-weight:400;
line-height:10px;
position:absolute;
top:-5px;
}
jQuery:
$("h2").hover(function () {
$(this).filter(':not(:animated)').animate({
lineHeight: '35px'
});
}, function () {
$(this).animate({
lineHeight: '0px'
});
});
第二
HTML
<div id="menu">
<h2>
<a>project one<br/> </a>
<span id="anim">
<a>number two<br/> </a>
<a>this would be project three<br/> </a>
<a>and number four<br> </a>
</span>
</h2>
</div>
jQuery:
$("h2").hover(function () {
$("#anim").filter(':not(:animated)').animate({
lineHeight: '35px'
});
}, function () {
$("#anim").animate({
lineHeight: '0px'
});
});
这里还有一个jsfiddle:
【问题讨论】:
标签: jquery css menu jquery-animate contextmenu