views:

601

answers:

2

I'm trying to make a basic drop down menu with animate and am running into the issue where I can't seem to figure out how to keep the dropdown part open until the mouse leaves. Is there an easy way to tell this to stay open? I know what I have is completely wrong regarding the .clickme mouseout function since it will unload the menu accordingly.

If anyone can help in this specific instance, I would be super grateful.

PREVIEW HERE http://cu3ed.com/ddmenu/

or below:

$(document).ready(function() {

$('.clickme').mouseover(function() {
    $('#slidebox').animate({
        top: '+=160'
    }, 200, 'easeOutQuad');
});

$('.clickme').mouseout(function(){
    $('#slidebox').animate({
        top: '-=160'
    }, 200, 'easeOutQuad')
});

});

I would like to keep this as simple and clean as possible. I know the CSS is all crazy but it's totally preliminary.

THANKS!!!

A: 

Check out jquery hoverIntent

Frank Malina
I've actually been reading about hoverIntent pretty much immediately after I posted this lol. Thanks!
Ce.
+1  A: 

This should get you going without any markup changes:

$('.clickme, #slidebox').hover(function() {
  $('#slidebox').stop().animate({ top: '30px' }, 200, 'easeOutQuad');
}, function() {
  $('#slidebox').stop().animate({ top: '-130px' }, 200, 'easeOutQuad');
});

Since your elements aren't parent/child related, easier to put absolute positions on the menu (it has 130px in the CSS anyway), so no reason not to use the fact it has an absolute position. Give it a shot, I tested against your site, seems to be the behavior I'd want in a menu.

Nick Craver
Thanks Nick I will give this a shot.
Ce.
+1 my solution was very close to yours, but it had an annoying bug... yours works indeed fine :)
Felix Kling
Ideally, would I want to change this into a parent/child scenario in the long run?
Ce.
@Ce - A child element would be different...but not necessarily *easier* in this case. If later you had multiple slide downs, then yes, I would make them child elements. Then, you could initially hide it and just give it a `slideToggle()` and the same easing effect.
Nick Craver
Ok. I'll look into this as the main nav on the menu I am actually creating will have 2 slide downs in the end. Would I be dropping animate for slideToggle or combining the two? I'll do some research... :)
Ce.
@Ce - You'd do something actually simpler, just position it at the bottom of the menu, 30px top or whatever with CSS, then something like this to animate: `$('.clickme').hover(function() { $(this).children('div').animate({height: 'toggle'}, 200, 'easeOutQuad'); });`
Nick Craver
@Nick this kindof gives more of a blind effect of which I was trying to avoid. I like the actual slide down and everything comes with it style rather than it's there and just gets revealed. Or maybe I had implemented it wrong. Thanks for the insight though. I've dug myself deeper into this.
Ce.