473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Jquery horizontal menu work on click

347 100+
I have a horizontal menu that uses the following jquery to work

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () {
  2. // <![CDATA[
  3.     var timeout    = 500;
  4.     var closetimer = 0;
  5.     var ddmenuitem = 0;
  6.  
  7.     function ddmenu_open(){
  8.         ddmenu_canceltimer();
  9.            ddmenu_close();
  10.            ddmenuitem = $(this).find('ul').css('visibility', 'visible');
  11.            $('#biog').css('visibility', 'hidden');
  12.     }
  13.  
  14.     function ddmenu_close(){
  15.         if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
  16.         $('#biog').css('visibility', 'visible');
  17.     }
  18.  
  19.     function ddmenu_timer(){
  20.         closetimer = window.setTimeout(ddmenu_close, timeout);
  21.     }
  22.  
  23.     function ddmenu_canceltimer(){ 
  24.         if(closetimer){ 
  25.             window.clearTimeout(closetimer);
  26.                 closetimer = null;
  27.     }}
  28.  
  29.     $(document).ready(function(){ 
  30.         $('#ddmenu > li').bind('mouseover', ddmenu_open)
  31.         $('#ddmenu > li').bind('mouseout',  ddmenu_timer)
  32.     });
  33.  
  34.     document.onclick = ddmenu_close;
  35. // ]]>  
  36. });
this works fine but i want to get the submenu to appear on click instead of on mouseover but still dissapear when the mouse goes out of the menu

i tried changing the

$('#ddmenu > li').bind('mouseover', ddmenu_open) line to

$('#ddmenu > li').bind('click', ddmenu_open)

$('#ddmenu > li').click(ddmenu_open)

and

$('#ddmenu > li').on('click', ddmenu_open)

but none of these worked

any ideas??
Mar 26 '13 #1
1 1635
colinod
347 100+
Figured this out just removed the

document.onclick = ddmenu_close;

line at the end

Now i have a problem closing the menu i want to close on mouse out so my jquery now is

at the moment i have a different id for each submenu

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () {
  2. // <![CDATA[
  3.     var timeout    = 500;
  4.     var closetimer = 0;
  5.     var ddmenuitem = 0;
  6.  
  7.     function ddmenu_open(){
  8.         ddmenu_canceltimer();
  9.            ddmenu_close();
  10.            ddmenuitem = $(this).find('ul').css('visibility', 'visible');
  11.            $('#biog').css('visibility', 'hidden');
  12.     }
  13.  
  14.     function ddmenu_close(){
  15.         if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
  16.         $('#biog').css('visibility', 'visible');
  17.     }
  18.  
  19.     function ddmenu_timer(){
  20.         closetimer = window.setTimeout(ddmenu_close, timeout);
  21.     }
  22.  
  23.     function ddmenu_canceltimer(){ 
  24.         if(closetimer){ 
  25.             window.clearTimeout(closetimer);
  26.                 closetimer = null;
  27.     }}
  28.  
  29.     $(document).ready(function(){ 
  30.         $('#ddmenu > li').bind('click', ddmenu_open);
  31.         $('#ulAgesid').bind('mouseout',  ddmenu_timer);
  32.         $('#ulUKAccentsid').bind('mouseout',  ddmenu_timer);
  33.         $('#ulStylesid').bind('mouseout',  ddmenu_timer);
  34.         $('#ulWorldAccentsid').bind('mouseout',  ddmenu_timer);
  35.         $('#ulForeignLanguagesid').bind('mouseout',  ddmenu_timer);
  36.     });
  37.  
  38.  
  39. // ]]>  
  40. });
problem i have is if you go onto the ages for the example i have coloured it red, if you stay in the red area all is fine but once you try and go over the button the menu closes

page can be seen here

http://www.yaketyyak.co.uk/newpages/...&voicetype=All
Mar 27 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ansgar Hein | last post by:
I have been playing around with several different versions for a horizontal menu, but I haven't been able to build a horizontal navigation based on the vertical one featured on www.alistapart.com...
5
by: Peter Cartwright | last post by:
This works in IE6. A horizontal menu made from a table with the space created by a td class="gap". All tds are rendered as inline elements except for .gap. So links are equidistantly spaced. This...
2
by: Craig van Nieuwkerk | last post by:
Hi. I am trying to create a horizontal menu like the one here http://www.milonic.com/menusample25.php where the drop down menu for each item it horizontal on a new row instead of vertical. Another...
5
by: McGeeky | last post by:
I am looking for a horizontal menu that has the "two row" layout - where the top row contains the top level menu items and the second contains the sub menu items. When a menu item is selected from...
0
by: Randy Smith | last post by:
Hi, For some reason, I am unable to get the child entries to work in a horizontal Menu control. Is there a property that I've failed to set? The menu entries are supposed to look like this:...
1
by: Stephen | last post by:
Hi From an example supplied with Visual Web Developer Express 2005, I am trying to build a "horizontal menu" with drop down links. In the example below I have added: url="mouse.aspx?/"> to...
2
by: Sergio E. | last post by:
Hi group, I write this post with the following question: How can I to build an absolutely horizontal menu?, This is because I can't find how can I configure the menu component of asp.net 2.0...
0
by: nonsensitor | last post by:
I would like to provide a scalable horizontal menu. Here's the twist: I want to keep the menu items on a single line for as many 'upscales' as possible. So I basically need 2 solutions: 1) For...
1
by: brixton | last post by:
Hello, silly problem maybe, but... I'm trying to get a horizontal menu to work with DIVs but I'm having trouble getting the menu items to "fill" the menu DIV. Basically I have a surrounding...
2
by: taras | last post by:
I have a problem with making horizontal menu with css. The problem is that menu should be right aligned, but items in sub menus should be left aligned. To make horizontal menu float:right property...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.