CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   jQuery navigation hiding before I can click menu items (http://www.codingforums.com/showthread.php?t=287469)

Chrys 02-11-2013 07:54 PM

jQuery navigation hiding before I can click menu items
 
I have a very simple navigation where I am using jquery to hide and show submenues on mouseover and hide them on mouseleave. When you hover over the main navigation it shows like it should but when you try to move your mouse down to click on the submenu items they hide. UGH!! Im not sure what to do about this.

I know from trial and error that it the speed that is killing it for me. When I remove the 400 it works fine but I that shouldn't affect the code that it is. Even if I add "slide inside the show function it still acts funny."
Does anyone have any ideas?

Code:

function nav(){
$('div#nav ul li').mouseover(function() {
$(this).find('ul').show(400);
});

$('div#nav ul li').mouseleave(function() {
$('div#nav ul li ul').hide();
});

$('div#nav ul li ul').mouseleave(function() {
$('div#nav ul li ul').hide();;
});
};

$(document).ready(function() {nav();});


Chrys 02-13-2013 02:32 PM

Does anyone have any ideas why the animation wont work?

VIPStephan 02-13-2013 03:12 PM

Without further looking into it I notice a syntax error:
Code:

$('div#nav ul li ul').hide();;
There is one semicolon too much.

For everything else we need to see more of your site – a link to a live example would be good. Alternatively there are sites like http://jsbin.com/, for example, where you can test your code and show it to others.

Chrys 02-13-2013 04:34 PM

SIMPLE sliding jquery navigation-works great now!
 
I figured it out. I was trying to be too specific with the hide script and I was hiding my menu when I was leaving particular elements within the list item. LOL! This is my script and it works well now. I also added in the click to toggle part because when you are on a mobile device the menu wont hide because there is no mouseleave. :-)

Code:

function nav(){
$('div#nav ul li').mouseover(function() {
$(this).find('ul').show("fast");
});

$('div#nav ul li').mouseleave(function() {
$(this).find('ul').hide("fast");
});

$('div#nav ul li').click(function() {
$(this).find('ul').toggle("fast");
});
};



All times are GMT +1. The time now is 02:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.