473,379 Members | 1,542 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,379 software developers and data experts.

How to open nested menu from root level verticle menu

245 100+
Hi,
I have made a vertical menu using ul li & jQuery with some animate effect. Now what i want that when i mouse over to a link who have sub menu then it shows the sub menu and when mouse out it hide the sub menu of that link.

For example I have the following navigation menu
Home
About Us
->Profile
->Mission Statement
Services
Portfolio
Contact Us

When i mouse over to About us it shows me sub menu (Profile, Mission Statement)towards right. Can any one guide me how can I do this...?
Secondly when i mouse over the existing main menu i am giving it some animate effect and also try to change it's background color. It gives the animate effect but do not change the background color. Can you please also guide me in this regard as well.

Here is my Code of existing navigation

HTML
Expand|Select|Wrap|Line Numbers
  1. <div id="sidebar">
  2.     <ul id="nav">
  3.         <li><a href="#.">Home</a></li>
  4.         <li><a href="#.">About Us</a></li>
  5.         <li><a href="#.">Services</a></li>
  6.         <li><a href="#.">Portfolio</a></li>
  7.         <li><a href="#.">Contact Us</a></li>
  8.     </ul>
  9. </div>
  10.  
CSS
Expand|Select|Wrap|Line Numbers
  1. #nav {
  2.     margin-top: 50px;
  3. }
  4. #nav {
  5.     list-style: none outside none;
  6.     margin: 73px 0 0 0;
  7.     overflow: hidden;
  8.     padding: 0;
  9.     position: relative;
  10.     text-align: right;
  11.     white-space: nowrap;
  12.     width: 275px;
  13.     z-index: 10;
  14. }
  15. #nav li {
  16.     height: 30px;
  17.     margin-bottom: 6px;
  18.     width: 275px;
  19. }
  20. #nav li a {
  21.     background: rgba(255, 255, 255, 0.11);
  22.     color: rgba(255, 255, 255, 0.65);
  23.     display: block;
  24.     float: right;
  25.     font: 14px/14px Arial,Helvetica,sans-serif;
  26.     letter-spacing: 1px;
  27.     padding: 8px 8px 6px 45px;
  28.     text-decoration: none;
  29.     width: auto;
  30. }
  31.  
JavaScript
Expand|Select|Wrap|Line Numbers
  1. $('#nav li').hover(
  2.         function () {
  3.             $(this).children().stop().animate(
  4.                 {paddingLeft: 230, paddingRight: 15, backgroundColor: "#e01a33"}, { queue:false, duration:1000, easing: 'swing'}
  5.             );
  6.         },
  7.         function () {
  8.             $(this).children().stop().animate(
  9.                 {paddingLeft: 45, paddingRight: 8, backgroundColor: "#e01a33"}, {queue:false, duration:600, easing: 'swing'}
  10.             );
  11.         }
  12.     );
  13.  
here is the Live demo of my work.

Kindly help me out to sort out my problem. I will be really thankful to you
May 10 '12 #1
1 2132
neovantage
245 100+
I have achieved it up to 90%. I used SuckerTree UL menus for this. But still i have a issue and that is When i mouse over to my nested menu link about us it apply the animate effect on li>a as well as ul (which is nested one). All I want that it apply on the li>a element only. Here is my updated Code.

HTML
Expand|Select|Wrap|Line Numbers
  1. <div id="sidebar">
  2.             <div class="suckerdiv">
  3.                 <ul id="suckertree1">
  4.                     <li><a href="#.">Home</a></li>
  5.                     <li><a href="#.">About Us</a>
  6.                         <ul>
  7.                                <li><a href="#.">Profile</a></li>
  8.                             <li><a href="#.">Mission, Vision &amp; Values</a></li>
  9.                         </ul>
  10.                     </li>
  11.                     <li><a href="#.">Services</a></li>
  12.                     <li><a href="#.">Portfolio</a></li>
  13.                     <li><a href="#.">Contact Us</a></li>
  14.                 </ul>
  15.             </div>
  16.         </div>
  17.  
CSS
Expand|Select|Wrap|Line Numbers
  1. #sidebar {
  2.     background: rgba(5, 2, 0, 0.85);
  3.     min-height: 100%;
  4.     padding: 0;
  5.     position: fixed;
  6.     width: 275px;
  7.     border-right: 5px solid #e01a33;
  8. }
  9. .suckerdiv {
  10.     margin-top: 73px;
  11. }
  12. .suckerdiv ul{
  13.     margin: 0;
  14.     padding:0;
  15.     list-style-type: none;
  16.     width: auto;
  17.     float: right;
  18. }
  19. .suckerdiv ul li{
  20.     position: relative;
  21.     text-align: right;
  22.     margin-bottom: 6px;
  23.     height: 30px;
  24. }
  25. /*Sub level menu items */
  26. .suckerdiv ul li ul{
  27.     position: absolute;
  28.     z-index: 999;
  29.     width: 220px; /*sub menu width*/
  30.     top: 0;
  31.     visibility: hidden;
  32.     border-left: 5px solid #e01a33;
  33. }
  34. .suckerdiv ul li ul li{
  35.     text-align:left;
  36.     background: #000;
  37. }
  38. .suckerdiv ul li ul li a{
  39.     background: #000;
  40.     text-align:left;
  41.     padding: 8px 8px 6px 10px;
  42.     float: left;
  43. }
  44. /* Sub level menu links style */
  45. .suckerdiv ul li a{
  46.     display: block;
  47.     overflow: auto; /*force hasLayout in IE7 */
  48.     color: #e8e8e8;
  49.     text-decoration: none;
  50.     padding: 8px 8px 6px 45px;
  51.     background: rgba(255, 255, 255, 0.11);
  52.     width: auto;
  53.     float: right;
  54. }
  55. .suckerdiv ul li a:hover{
  56.     *background-color: #6F2F53;
  57. }
  58. /* Holly Hack for IE \*/
  59. * html .suckerdiv ul li { float: left; height: 1%; }
  60. * html .suckerdiv ul li a { height: 1%; }
  61.  
JavaScript for Sucker div
Expand|Select|Wrap|Line Numbers
  1. var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas
  2. function buildsubmenus(){
  3. for (var i=0; i<menuids.length; i++){
  4.   var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
  5.     for (var t=0; t<ultags.length; t++){
  6.     ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
  7.         if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
  8.             ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
  9.         else //else if this is a sub level submenu (ul)
  10.           ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
  11.     ultags[t].parentNode.onmouseover=function(){
  12.     this.getElementsByTagName("ul")[0].style.display="block"
  13.     }
  14.     ultags[t].parentNode.onmouseout=function(){
  15.     this.getElementsByTagName("ul")[0].style.display="none"
  16.     }
  17.     }
  18.         for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
  19.         ultags[t].style.visibility="visible"
  20.         ultags[t].style.display="none"
  21.         }
  22.   }
  23. }
  24.  
  25. if (window.addEventListener)
  26. window.addEventListener("load", buildsubmenus, false)
  27. else if (window.attachEvent)
  28. window.attachEvent("onload", buildsubmenus)
  29.  
JavaScript for animate Effect
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function(){
  2.     $('#suckertree1>li').hover(
  3.         function () {
  4.             $(this).children().stop().animate(
  5.                 {paddingLeft: 150, backgroundColor: "#e01a33"}, { queue:false, duration:1000, easing: 'swing'}
  6.             );
  7.         },
  8.         function () {
  9.             //$('ul#suckertree1 li ul').css("padding-left","10px");
  10.             $(this).children().stop().animate(
  11.                 {paddingLeft: 45, backgroundColor: "#e01a33"}, {queue:false, duration:600, easing: 'swing'}
  12.             );
  13.         }
  14.     );
  15. });
  16.  

Can some one tell me the solution.

Thanks in Advance
May 10 '12 #2

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

Similar topics

2
by: Robb Meade | last post by:
Hi all, I've written a small form handler script which should work for 'all' (term used loosely) forms... It will email the company, send courtesy emails to the form filler and save data to a...
3
by: Korivo | last post by:
Im getting this error while trying to read a xml file that i receive from a POST heres the code: Dim MyXmlReader As XmlTextReader Dim strNodeResult As String Dim NodeType As XmlNodeType Dim...
1
by: jm | last post by:
I get "data at the root level is invalid." I have changed security for the IUSR_xx to be in the adminstrators (tried anonymous access); changed all the file security I could; tried virtual...
1
by: CW | last post by:
I have been using (vertical) data list to simulate menus on left pane of pages (I don't use drop-down and pull-down menus because javascript must be enabled). However, the problem with data list is...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
13
by: Larry Bud | last post by:
Trying to conditionally remove menu items of the 2.0 .NET menu item control and I'm stumped. This removed a root level item: Menu1.Items.Remove(Menu1.FindItem("Administration")) But this...
4
by: johnsonkt | last post by:
hi all , when m trying to validate my xml using xsd file it gives me the following error "Data at the root level is invalid. Line 1, position 1" i tried to open the XML file using IE and there...
4
omerbutt
by: omerbutt | last post by:
hi i am making a css verticle menu with <ui>and <li> and i want to open a popup window hen i click on a link lets say if this is the link <ui> <li><a href="AddNewRecord.asp">Add New...
1
by: sabamasap | last post by:
is there a difference between nested and multi-level array according to their running time? actually what is the differences between them?
2
by: Cirene | last post by:
My ASP.NET project builds fine (VS2008). I added a new web deployment project. When I try to build it I get: Data at the root level is invalid. Line1, position 1. (The file is web.config,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.