i have this simple example here : http://jsfiddle.net/pTyvc/1/ i don't want the sub_menu div to slideUp if mouse is over it any help ? thanks
- It doesn't collapse for me. Perhaps your browser doesn't like you.pimvdb– pimvdb2012-02-15 14:12:57 +00:00Commented Feb 15, 2012 at 14:12
- he means if you move to the blue block. it does it for me too.Teun Pronk– Teun Pronk2012-02-15 14:17:26 +00:00Commented Feb 15, 2012 at 14:17
- Oops sorry, it doesn't like me either :)pimvdb– pimvdb2012-02-15 14:19:26 +00:00Commented Feb 15, 2012 at 14:19
- Its because of the mouseleave event.Teun Pronk– Teun Pronk2012-02-15 14:26:27 +00:00Commented Feb 15, 2012 at 14:26
- ya it's because the mouseleave so how to keep it showing till the sub_menu mouseleavePHP User– PHP User2012-02-15 14:36:50 +00:00Commented Feb 15, 2012 at 14:36
| Show 1 more comment
1 Answer
You'll have to use mouseover because mouseenter is not fired when you move from a child element to the parent element.
Also, when you mouseover a sub menu, you'll have to .stop() the animation to keep it from sliding up. The same applies for moving the mouse from the sub menu to the parent element.
$(".menu_item").mouseover(function(){ $(this).addClass("selected") .children().stop().slideDown(500); }); $(".menu_item").mouseout(function(e){ $(this).removeClass("selected") .children(".sub_menu").slideUp(500); }); $(".sub_menu").mouseover(function() { $(this).stop(); }); 4 Comments
pimvdb
@Yasser: I see it actually starts acting weird if you move the mouseover the sub menu when it's sliding down. This seems a bit complicated.
Hadas
Add '.animate({height:'100px'});' after 'stop()' in order the div will continue to slide down to the full height
pimvdb
@Hadas: Thanks, though it makes for some delay when hovering now.
Hadas
@pimvdb Sure,it stop and only then animate