I came up with a solution to this based on an answer to another question.
I set the containing <div>
to have a height
and width
of 0
with overflow: visible
. Then I gave the containing <div>
the hover event. This ensures that the event is only triggered when the mouse enters or leaves its children (my menu and handle <div>
s).
Here is a JSFiddle for posterity.
HTML:
<div id="container">
<div id="menu">Menu</div>
<div id="handle">+</div>
</div>
JS:
var slideIn = function () {
$('#container').stop(true);
$('#container').animate({
left: '0px'
}, 'fast');
};
var slideOut = function () {
$('#container').stop(true);
$('#container').animate({
left: '-190px'
}, 'fast');
};
$('#container').hover(slideIn, slideOut);
CSS:
#container {
width:0;
height:0;
overflow:visible;
position:absolute;
left:-190px;
}
#handle {
padding:10px;
width:auto;
height:auto;
background: rgba(0, 0, 0, 0.8);
font-size:18px;
color:#FFF;
display:inline-block;
border-bottom-right-radius:3px;
}
#menu {
background: rgba(0, 0, 0, 0.8);
width:195px;
height:300px;
float:left;
display:inline-block;
border-bottom-right-radius:3px;
}