Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    UK, South Wales, Newport
    Posts
    21
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Hide sub-menu when not focused

    The Code
    Basic nav bar made from a table in html. When the menu item "cakes" is hovered i want a dropdown list called "sub-links" to appear. Which it does.

    The Question
    I wana keep the dropdown list shown when its focused, but as soon as it looses focus i want it to hide.

    Code:
    	//Toggle sub-menu
    	$('.sub-links').hide();
    	$('.NavBar').find('#cakes').hover(function(){
    		$('.sub-links').show();
    		//if the sub menu has focus then show it, if not then hide it
    	if($('sub-links').focus=false){
    		$(this).hide();
    	}
    	});
    Thank You
    Last edited by samz; 12-08-2011 at 12:02 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,798
    Thanks
    8
    Thanked 131 Times in 129 Posts
    you want something like this?

    Code:
    	$('.sub-links').hide();
    	$('.NavBar #cakes, .sub-links').hover(function(){
    		$('.sub-links').show();
    	}, function(){
    		$('.sub-links').hide();
    	});
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • Users who have thanked harbingerOTV for this post:

    samz (12-09-2011)

  • #3
    New Coder
    Join Date
    Sep 2011
    Location
    UK, South Wales, Newport
    Posts
    21
    Thanks
    8
    Thanked 0 Times in 0 Posts
    thats exactly what i wanted...buuuutttt.....its sorta glitchy.

    once "cakes" is highlighted and the dropdown menu is shown, you have to quickly move the mouse onto the dropdown otherwise it will hide.

    Is ther a way to add a delay to the hide bit? should i even consider that method?
    Last edited by samz; 12-09-2011 at 03:18 AM.

  • #4
    New Coder
    Join Date
    Sep 2011
    Location
    UK, South Wales, Newport
    Posts
    21
    Thanks
    8
    Thanked 0 Times in 0 Posts
    0o0o0 i did it....i just moved the dropdown table a lil closer to the NavBar.
    And now i can slowly move onto the dropdown menu before it vanishes.

    Did you have a better idea in mind tho? My method seems a bit...childish/unproffesional lol
    Last edited by samz; 12-09-2011 at 03:32 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •