How can i say with jQuery mouseover to ignore the empty Space between elements, so the mouseover is still active on an element which is positioned outside of the parent element?
Here's a snippet. The yellow list should be active on mouseover and still active if i go to this list. Currently the mouseout is of course fired if i want to go the the yellow list.
The yellow list should be hided if i leave the yellow list and the current link of the blue list.
$("ul > li")
.mouseover(function() {
$(this).addClass('active').has('ul').addClass('has-children');
if($(this).hasClass('has-children')){
$(this).find('ul').first().addClass('visible');
}
})
.mouseout(function() {
$(this).removeClass('active');
$(this).has('ul').removeClass('has-children visible');
$(this).find('ul').removeClass('visible');
});
body {
background:red;
}
div {
position:relative;
}
ul {
background:blue;
color:white;
padding:10px;
}
div > ul {
position:absolute;
left:0;
}
div ul > li > ul {
position:absolute;
left:200px;
top:0;
display:none;
}
.visible {
display:block;
}
li.active ul {
background:yellow;
color:black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<ul>
<li>Link 1
<ul>
<li>Link 2</li>
</ul>
</li>
<li>Foo</li>
<li>Bar</li>
</ul>
</div>