I have an element that needs to slideDown when another element is hovered over, and remain visible when it is hovered over itself. Due to issues involving a design with a lot of overlapping elements and heavy use of z-index, I cannot nest the sliding element inside the hovered over element; they cannot even be siblings.
The HTML:
<div class="a">
<div class="b">
<div class="c">
<nav class="navvy">
<ul>
<li class="active">
<a href="#" class="one">One</a>
</li>
<li>
<a href="#" class="two">Two</a>
</li>
</ul>
</nav><!--nav-1-->
</div><!--c-->
</div><!--b-->
</div><!--a-->
<div class="slidedown slidedown-one">
<div class="slide-content">
One - text.
</div><!--slide-content-->
</div><!--slidedown-->
<div class="slidedown slidedown-two">
<div class="slide-content">
Two - text.
</div><!--slide-content-->
</div><!--slidedown-->
The jQuery (note: I'm using the hoverIntent plugin):
//Hide all slidedown divs
$('.slidedown').hide();
//Find the active class
var activeCl = $('.navvy').children('ul').find('.active').children('a').attr('class').split(' ')[0];
//Slide it down
var downSlide = function() {
activeCl = $(this).attr('class').split(' ')[0];
$('.slidedown-'+activeCl).slideDown(1000);
};
//Slide it up
var upSlide = function() {
activeCl = $(this).attr('class').split(' ')[0];
$('.slidedown-'+activeCl).delay(1000).slideUp(1000);
};
//Slide on hover
var slideHover = function() {
$('.navvy').children('ul').find('li').children('a').hoverIntent({
over: downSlide,
out: upSlide
});
};
slideHover();
It slides up and down fine, but I need it to not slide back up again when the mouse is inside of the div that slid down.
EDIT: Here is a JSFiddle with the code: http://jsfiddle.net/qeLVU/2/
Your code looks like you're over thinking this a bit. Just slide down or up when you hover on or off the
nav
link, and the same with thediv
itself.http://jsfiddle.net/cJWn8/