【发布时间】:2014-07-09 02:05:13
【问题描述】:
我在使用 jQuery 时遇到了 mouseenter/mouseleave 问题,显然,当我将鼠标移到子元素上时,它会触发 mouseleave 动作。
我有http://jsfiddle.net/theylooksotired/ucarF/1/中的所有代码
HTML:
<div class="menuAll">
<div class="menuIns">
<div class="menuInsTop">
<a href="http://localhost/ilki/expertise">Expertise</a>
</div>
<div class="menuInsBottom" style="display: none;">
<div class="menuInsBottomIns">
<a href="http://localhost/ilki/expertise#notre-offre">Notre offre</a>
<a href="http://localhost/ilki/expertise#conseil">Conseil</a>
<a href="http://localhost/ilki/expertise#architecture">Architecture</a>
<a href="http://localhost/ilki/expertise#formation">Formation</a>
</div>
</div>
</div>
<div class="menuIns">
<div class="menuInsTop">
<a href="http://localhost/ilki/carrieres">Carrierès</a>
</div>
<div class="menuInsBottom" style="display: none;">
<div class="menuInsBottomIns">
<a href="http://localhost/ilki/expertise#notre-offre">Notre offre</a>
<a href="http://localhost/ilki/expertise#conseil">Conseil</a>
<a href="http://localhost/ilki/expertise#architecture">Architecture</a>
<a href="http://localhost/ilki/expertise#formation">Formation</a>
</div>
</div>
</div>
<div class="menuIns">
<div class="menuInsTop">
<a href="http://localhost/ilki/a-propos">A propos</a>
</div>
<div class="menuInsBottom" style="display: none;">
<div class="menuInsBottomIns">
<a href="http://localhost/ilki/expertise#notre-offre">Notre offre</a>
<a href="http://localhost/ilki/expertise#conseil">Conseil</a>
<a href="http://localhost/ilki/expertise#architecture">Architecture</a>
<a href="http://localhost/ilki/expertise#formation">Formation</a>
</div>
</div>
</div>
<div class="menuIns">
<div class="menuInsTop">
<a href="http://localhost/ilki/echangeons">Echangeons</a>
</div>
<div class="menuInsBottom" style="display: none;">
<div class="menuInsBottomIns">
<a href="http://localhost/ilki/expertise#notre-offre">Notre offre</a>
<a href="http://localhost/ilki/expertise#conseil">Conseil</a>
<a href="http://localhost/ilki/expertise#architecture">Architecture</a>
<a href="http://localhost/ilki/expertise#formation">Formation</a>
</div>
</div>
</div>
<div class="menuIns">
<div class="menuInsTop">
<a href="http://localhost/ilki/contact">Contact</a>
</div>
</div>
</div>
JS:
$('.menuIns').mouseenter(function(){
$(this).find('.menuInsBottom').css('display', 'block');
});
$('.menuIns').mouseleave(function(){
$(this).find('.menuInsBottom').css('display', 'none');
});
CSS:
.menuAll {
text-align: center;
padding-top: 50px;
}
.menuAll a {
font-size: 1.1em;
color: #A2B5BE;
padding: 0px 5px;
}
.menuInsBottom {
position: absolute;
left: 10px;
top: 80px;
display: none;
}
.menuInsBottom a{
padding: 5px 10px;
padding-right: 50px;
display: block;
font-size: 0.9em;
}
.menuInsBottom a:hover{
background: #ECF0F2;
}
.menuInsBottomIns {
background: #FFF;
border:2px solid #A2B5BE;
text-align: left;
}
.menuIns,
.menuInsTop {
display: inline;
}
.menuIns {
position: relative;
cursor: pointer;
padding-top: 50px;
}
.menuIns:hover {
color: #000;
}
.menuIns:hover a{
color: #000;
}
我在这里搜索了几个问题,但似乎没有一个是我要找的。p>
【问题讨论】:
-
这通常是这样工作的,当鼠标离开带有事件处理程序的元素时,执行该事件的回调。