我有一个隐藏在屏幕外的简单侧边菜单,当它悬停在特定区域时我想显示它。它工作得很好,但是如果鼠标移到菜单上,它会认为它超出了该区域并返回。然后,一旦发生这种情况,它将与我想要的交互相反:
<div class="menu-hover">
Hover Mouse Here
</div>
<div class="side-menu">
<div class="btn-group btn-group-vertical">
<button id="metro" class="btn">Metro</button>
<button id="list" class="btn">List</button>
<button id="grid" class="btn">Grid</button>
</div>
</div>
CSS:
.side-menu {
background-color: #333;
border: 1px solid #444;
color: #fff;
display: block;
font-size: 15px;
font-weight: 700;
left: -96px;
padding: 15px;
text-decoration: none;
top: 0;
height: 100%;
position: fixed;
z-index: 5;
cursor: pointer;
}
JS:
$(".menu-hover").hover(
function () {
var $lefty = $(".side-menu");
$lefty.animate({
left: parseInt($lefty.css('left')) < -95 ?
$lefty.css('left') == 0 :
-96
});
});