JavaScript - Navigation Menu Both Submenu And Parent Class Active
I have a navigation menu with one level of submenu, and the code that I have allowes me when I click on the parent, the submenu opens (and remains open). When I click on a subitem, the page travels to that url, but the code that I have compares the document.location to the href of the menu items and display the submenu.
Now the active page is hightlighted, but the parent isn't (if the active page is a submenu). So what I want is that when a subitem is active, also it's parent should be active, for example: main_item_1 main_item_2 --sub_item_1 --sub_item_2 In this case when sub_item_2 is active, also main_item_2 should be. I have tried to use parent(), parents(), but none worked the right way, or at least for me the way I want it. So here is the code I use: Code: $('#topnav ul li ul.submenu li a').click(function(e){ if ($(this).attr('class') != 'active'){ $('#topnav ul li a').removeClass('active'); $(this).addClass('active'); } }); $('a').filter(function(){ return this.href === document.location.href; }).addClass('active') $("ul.submenu > li > a").each(function () { var currentURL = decodeURIComponent(document.location.href); var thisURL = $(this).attr("href"); if (currentURL.indexOf(thisURL) != -1) { $(this).parents("ul.submenu").css('display', 'block'); } }); $('#topnav > ul > li > a').each(function(){ var currURL = decodeURIComponent(document.location.href); var myHref= $(this).attr('href'); if (currURL.match(myHref)) { $(this).addClass('active'); //$('a', $('.active').parents("li:last")).addClass('active'); $(this).parent().find("ul.submenu").css('display', 'block'); } }); The middle group code is for the subitem, so the code to make the parent also active should be there I think. When I add the following line to the middle group (after the $(this).parents part): Code: $(this).parents("#topnav ul li").addClass('parent'); I am able to make the background of the top parent different, because the parent class changes the background color, but should also change the color of the menu text (parent), but .... not only the most top li has the parent class, also the li which is around the active subitem, which should only be the parent. Please help. Similar TutorialsHi Exprts, I am using a (anylink)javascript menu from dynamic drive. Basically I am having a design issue but posting the problem here because I think this can be fixed through JS. Please download the attached files. You will see the menu & the sub menu on mouse over. Problem is that.... when the submenu appears & I take my mouse to the sub menu, the parent item hover style disappears. I mean, it doesn't look active. I just want the parent item active when users moves his/her mouse to sub menu. Thats all. Please suggest me any solutions for this. Thank you in advance. I need some help with a drop down menu. I am working on a site with a left menu that slides out, and I've converted it to the top to drop down. So far, it is working ok, but the submenu items need to be below the parent, preferably left aligned. I have played with it a bit and so far can't seem to achieve what I want. See below where I'm clicking Resources and the menu is way too high and over to the right. Thanks in advance for any help. : ) Code: //** Dynamic Drive Equal Columns Height script v1.01 (Nov 2nd, 06) //** http://www.dynamicdrive.com/style/bl...height-script/ var ddequalcolumns=new Object() //Input IDs (id attr) of columns to equalize. Script will check if each corresponding column actually exists: ddequalcolumns.columnswatch=["sidebar-a", "content"] ddequalcolumns.setHeights=function(reset){ var tallest=0 var resetit=(typeof reset=="string")? true : false for (var i=0; i<this.columnswatch.length; i++){ if (document.getElementById(this.columnswatch[i])!=null){ if (resetit) document.getElementById(this.columnswatch[i]).style.height="auto" if (document.getElementById(this.columnswatch[i]).offsetHeight>tallest) tallest=document.getElementById(this.columnswatch[i]).offsetHeight } } if (tallest>0){ for (var i=0; i<this.columnswatch.length; i++){ if (document.getElementById(this.columnswatch[i])!=null) document.getElementById(this.columnswatch[i]).style.height=tallest+"px" } } } ddequalcolumns.resetHeights=function(){ this.setHeights("reset") } ddequalcolumns.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload) var tasktype=(window.addEventListener)? tasktype : "on"+tasktype if (target.addEventListener) target.addEventListener(tasktype, functionref, false) else if (target.attachEvent) target.attachEvent(tasktype, functionref) } ddequalcolumns.dotask(window, function(){ddequalcolumns.setHeights()}, "load") ddequalcolumns.dotask(window, function(){if (typeof ddequalcolumns.timer!="undefined") clearTimeout(ddequalcolumns.timer); ddequalcolumns.timer=setTimeout("ddequalcolumns.resetHeights()", 200)}, "resize") /************************************************************************************************************ (C) www.dhtmlgoodies.com, November 2005 This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. Terms of use: You are free to use this script as long as the copyright message is kept intact. However, you may not redistribute, sell or repost it without our permission. Thank you! www.dhtmlgoodies.com Alf Magne Kalleland ************************************************************************************************************/ var timeBeforeAutoHide = 700; // Microseconds to wait before auto hiding menu(1000 = 1 second) var slideSpeed_out = 10; // Steps to move sub menu at a time ( higher = faster) var slideSpeed_in = 10; var slideTimeout_out = 25; // Microseconds between slide steps ( lower = faster) var slideTimeout_in = 10; // Microseconds between slide steps ( lower = faster) var showSubOnMouseOver = true; // false = show sub menu on click, true = show sub menu on mouse over var fixedSubMenuWidth = false; // Width of sub menu items - A number(width in pixels) or false when width should be dynamic var xOffsetSubMenu = 0; // Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu var slideDirection = 'right'; // Slide to left or right ? /* Don't change anything below here */ var activeSubMenuId = false; var activeMainMenuItem = false; var currentZIndex = 1000; var autoHideTimer = 0; var submenuObjArray = new Array(); var okToSlideInSub = new Array(); var subPositioned = new Array(); function stopAutoHide() { autoHideTimer = -1; } function initAutoHide() { autoHideTimer = 0; if(autoHideTimer>=0)autoHide(); } function autoHide() { if(autoHideTimer>timeBeforeAutoHide) { if(activeMainMenuItem){ activeMainMenuItem.className=''; activeMainMenuItem = false; } if(activeSubMenuId){ var obj = document.getElementById('subMenuDiv' + activeSubMenuId); showSub(); } }else{ if(autoHideTimer>=0){ autoHideTimer+=50; setTimeout('autoHide()',50); } } } function getTopPos(inputObj) { var returnValue = inputObj.offsetTop; while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop; return returnValue; } function getLeftPos(inputObj) { var returnValue = inputObj.offsetLeft; while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft; return returnValue; } function showSub() { var subObj = false; if(this && this.tagName){ var numericId = this.parentNode.id.replace(/[^0-9]/g,''); okToSlideInSub[numericId] = false; var subObj = document.getElementById('subMenuDiv' + numericId); if(activeMainMenuItem)activeMainMenuItem.className=''; if(subObj){ if(!subPositioned[numericId]){ if(slideDirection=='right'){ subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + submenuObjArray[numericId]['parentDiv'].offsetWidth + xOffsetSubMenu + 'px'; }else{ subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + xOffsetSubMenu + 'px'; } submenuObjArray[numericId]['left'] = subObj.style.left.replace(/[^0-9]/g,''); subObj.style.top = getTopPos(submenuObjArray[numericId]['parentDiv']) + 'px'; subPositioned[numericId] = true; } subObj.style.visibility = 'visible'; subObj.style.zIndex = currentZIndex; currentZIndex++; this.className='activeMainMenuItem'; activeMainMenuItem = this; } }else{ var numericId = activeSubMenuId; } if(activeSubMenuId && (numericId!=activeSubMenuId || !subObj))slideMenu(activeSubMenuId,(slideSpeed_in*-1)); if(numericId!=activeSubMenuId && this && subObj){ subObj.style.width = '0px'; slideMenu(numericId,slideSpeed_out); activeSubMenuId = numericId; }else{ if(numericId!=activeSubMenuId)activeSubMenuId = false; } if(showSubOnMouseOver)stopAutoHide(); } function slideMenu(menuIndex,speed){ var obj = submenuObjArray[menuIndex]['divObj']; var obj2 = submenuObjArray[menuIndex]['ulObj']; var width = obj.offsetWidth + speed; if(speed<0){ if(width<0)width = 0; obj.style.width = width + 'px'; if(slideDirection=='left'){ obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px'; obj2.style.left = '0px'; }else{ obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' } if(width>0 && okToSlideInSub[menuIndex])setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_in); else{ obj.style.visibility = 'hidden'; obj.style.width = '0px'; if(activeSubMenuId==menuIndex)activeSubMenuId=false; } }else{ if(width>submenuObjArray[menuIndex]['width'])width = submenuObjArray[menuIndex]['width']; if(slideDirection=='left'){ obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px'; obj2.style.left = '0px'; }else{ obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' } obj.style.width = width + 'px'; if(width<submenuObjArray[menuIndex]['width']){ setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_out); }else{ okToSlideInSub[menuIndex] = true; } } } function resetPosition() { subPositioned.length = 0; } function initLeftMenu() { var isMSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false; var browserVersion = parseInt(navigator.userAgent.replace(/.*?MSIE ([0-9]+?)[^0-9].*/g,'$1')); if(!browserVersion)browserVersion=1; var menuObj = document.getElementById('dhtmlgoodies_menu'); var mainMenuItemArray = new Array(); var mainMenuItem = menuObj.getElementsByTagName('LI')[0]; while(mainMenuItem){ if(mainMenuItem.tagName && mainMenuItem.tagName.toLowerCase()=='li'){ mainMenuItemArray[mainMenuItemArray.length] = mainMenuItem; var aTag = mainMenuItem.getElementsByTagName('A')[0]; if(showSubOnMouseOver) aTag.onmouseover = showSub; else aTag.onclick = showSub; } mainMenuItem = mainMenuItem.nextSibling; } var lis = menuObj.getElementsByTagName('A'); for(var no=0;no<lis.length;no++){ if(!showSubOnMouseOver)lis[no].onmouseover = stopAutoHide; lis[no].onmouseout = initAutoHide; lis[no].onmousemove = stopAutoHide; } for(var no=0;no<mainMenuItemArray.length;no++){ var sub = mainMenuItemArray[no].getElementsByTagName('UL')[0]; if(sub){ mainMenuItemArray[no].id = 'mainMenuItem' + (no+1); var div = document.createElement('DIV'); div.className='dhtmlgoodies_subMenu'; document.body.appendChild(div); div.appendChild(sub); if(slideDirection=='right'){ div.style.left = getLeftPos(mainMenuItemArray[no]) + mainMenuItemArray[no].offsetWidth + xOffsetSubMenu + 'px'; }else{ div.style.left = getLeftPos(mainMenuItemArray[no]) + xOffsetSubMenu + 'px'; } div.style.top = getTopPos(mainMenuItemArray[no]) + 'px'; div.id = 'subMenuDiv' + (no+1); sub.id = 'submenuUl' + (no+1); sub.style.position = 'relative'; if(navigator.userAgent.indexOf('Opera')>=0){ submenuObjArray[no+1] = new Array(); submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no]; submenuObjArray[no+1]['divObj'] = div; submenuObjArray[no+1]['ulObj'] = sub; submenuObjArray[no+1]['width'] = sub.offsetWidth; submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,''); } sub.style.left = 1 - sub.offsetWidth + 'px'; if(browserVersion<7 && isMSIE)div.style.width = '1px'; if(navigator.userAgent.indexOf('Opera')<0){ submenuObjArray[no+1] = new Array(); submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no]; submenuObjArray[no+1]['divObj'] = div; submenuObjArray[no+1]['ulObj'] = sub; submenuObjArray[no+1]['width'] = sub.offsetWidth; submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,''); if(fixedSubMenuWidth)submenuObjArray[no+1]['width'] = fixedSubMenuWidth; } if(!document.all)div.style.width = '1px'; } } menuObj.style.visibility = 'visible'; window.onresize = resetPosition; } window.onload = initLeftMenu; Please where do I need to look to find such a script? I’ve been looking for 3 days now and I can’t find something that will have all of those. I need a floating horizontal dropdown menu, and submenu with mouse over description of the site. EX: menu 1 On the road ------- --------Restaurant .... .... ... .... ... .... .... .... ... .Mama house (home made cooking) .... .... ... .... ... .... .... .... ... .All fast food (only fast food get carb) .... .... ... .... ... Motel .... .... ... .... ... .... .... .... ... .No fleas motel (bugs free motel) .... .... ... .... ... .... .... .... ... .Pet free ( no pet allowed) Car rental Well I am sure you get the ideal. Where do I need to look or what would be the kind of scrip for that ? Java, html, css…. Please tell me to find the proper code for what I need. thanks Ok, first let me explain what I try to do. I have a menu with some items containing a submenu. The submenu's should open when a parent is clicked and contains submenu's, and when traveling to another page (from the item clicked, for example a parent of submenu item), the submenu should remain active and visible. When I click on a parent (at the moment the hrefs contain no links just #), the submenu opens. But when I click another main item, the submenu of the previous parent remain visible, and the submenu of the parent just clicked is also visible, while I only want the submenu of the parent clicked to be visible or when parent with no submenu the submenu should be invisible. So, here is the code I have so far: Code: <div id="topnav"> <ul> <li> <a href="index.html">Home</a> </li> <li> <a href="#">Over Meves</a> <ul class="submenu"> <li><a href="#" class="suba">Historie</a></li> <li><a href="#" class="suba">Onze mensen</a></li> <li><a href="#" class="suba">Werkzijze</a></li> </ul> </li> <li> <a href="vervolg3.html">Disciplines</a> <ul class="submenu"> <li><a href="vervolg.html" class="suba">Klimaatbeheersing</a></li> <li><a href="#" class="suba">Elektrotechniek</a></li> <li><a href="#" class="suba">Sanitaire techniek</a></li> <li><a href="#" class="suba">Energiebesparingstechniek</a></li> <li><a href="#" class="suba">Bouwfysica en geluid</a></li> <li><a href="#" class="suba">Diensten energiebesparing</a></li> </ul> </li> <li> <a href="#">Expertise</a> <ul class="submenu"> <li><a href="#" class="suba">Woningbouw & Utiliteit</a></li> <li><a href="#" class="suba">Zorg & Welzijn</a></li> <li><a href="#" class="suba">Milieu & Energie</a></li> <li><a href="#" class="suba">Beheer & Onderhoud</a></li> <li><a href="#" class="suba">EPA & EPC</a></li> <li><a href="#" class="suba">Legionella beheersing</a></li> </ul> </li> <li> <a href="#">Contact</a> <ul class="submenu"> <li><a href="#" class="suba">Adres & route</a></li> <li><a href="#" class="suba">Werken bij</a></li> </ul> </li> </ul> </div> The javascript: Code: <script type="text/javascript"> var ddmenuitem = 0; function jsddm_open() { jsddm_close(); ddmenuitem = $(this).find('ul.submenu').css('display', 'block'); } function jsddm_close() { if(ddmenuitem) ddmenuitem.css('display', 'none'); } $(document).ready(function() { $('#topnav > ul > li').bind('click', jsddm_open) $('#topnav ul li a.suba').click(function(e){ if ($(this).attr('class') != 'active'){ $('#topnav ul li a.suba').removeClass('active'); $(this).addClass('active'); } }); $("ul.submenu > li > a").each(function () { var currentURL = document.location.href; var thisURL = $(this).attr("href"); if (currentURL.indexOf(thisURL) != -1) { $(this).parents("ul.submenu").css('display', 'block'); } }); $('a').each(function () { var currentURL = document.location.href; var thisURL = $(this).attr('href'); if (currentURL = thisURL) { $(this).parents('ul.submenu').css('display', 'block'); } // else { // $(this).parents('ul.submenu').css('display', 'none'); // } }); }); </script> And the css: Code: #topnav ul { list-style: none; padding: 0; margin: 0; } #topnav ul li { float: left; margin: 0; padding: 0; } #topnav ul li a { padding: 5px 15px; color: #00537F; text-decoration: none; display: block; font-weight: bold; } #topnav ul li a:link { color: #FFF; text-decoration: none; } #topnav ul li a:visited { color: #FFF; text-decoration: none; } #topnav ul li a:hover { color: #FFF; text-decoration: underline; } #topnav ul li a.active { text-decoration: underline; color: #FFF; } /*#topnav ul li:hover .submenu { display:block; }*/ #topnav ul li ul.submenu { float: left; padding: 4px 0; position: absolute; left: 0; top: 24px; display: none; background: #e0e0e0; color: #00537F; } #topnav ul li ul.submenu a { display: inline; color: #00537F; padding: 4px 8px; } #topnav ul li ul.submenu li { border-right-width: 1px; border-right-style: solid; border-right-color: #00537F; } #topnav ul li ul.submenu li:last-child { border-right-style: none; } #topnav ul li ul.submenu a:link { color: #00537F; } #topnav ul li ul.submenu a:visited { color: #00537F; } #topnav ul li ul.submenu a:hover { text-decoration: underline; color: #00537F; } #topnav ul li ul.submenu li.active { text-decoration: underline; color: #00537F; } #topnav ul li ul.submenu a.active { text-decoration: underline; color: #00537F; } Hope I explained it clear. Thanks for any help. Hi everyone I have some problems with assigning a class to my included navagation menu. I would like to give the last clicked menu item a active class so I can style it but i have no clue how that works with javascript. as you can see i have three files two pages which included the same menu. Now I would like to set the first page to active because it would be the page the would start. but then when someone clicks the second page it should become inactive and set the active class to the secone link. if that makes sens. Is this possible with javascript? my pages: Page 1 PHP Code: <HTML> <BODY> <?php include "menu.php" ?> PAGE </BODY> </HTML> Page 2 PHP Code: <HTML> <BODY> <?php include "menu.php" ?> PAGE 2 </BODY> </HTML> menu.php PHP Code: <a href="page.php" class="active">page1</a> <a href="page2.php" class="noactive">Page2</a> thanks anyway
Ok...so here is what I have: Code: function myClass() { this.checkLogin = function(name,pwd) { if(name.length > 0 && pwd.length > 0) { $.ajax({async: false, type: "post", url: "url", dataType: "json", data: "data", success: this.parseData}); } } this.parseData = function(data) { this.status = data.status; alert(this.status); } this.getStatus = function() { alert(this.status); } } Everything works above. The first alert shows that this.status was set to 'error'. However, if I call myClass.getStatus(), I get undefined. How can I get the parseData function to set the variables in the parent function? Thanks! I'm trying to get this to work... I have a menu which has a submenu which is activated on mouse over with javascript and that part works just fine, but... I want to be able to have the submenu showned if the mainmenu is clicked... So if, as in example below, the page home is selected, the submenu is activated untill trhe mouse is hoovering over the "Cars" link, and when the mouse goes off the Cars link again the home submenu is activated... Hope this makes sense... Example below: Code: <script> sfHover = function() { var sfEls = document.getElementById("navbar").getElementsByTagName("li"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" hover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" hover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); </script> <ul class="navbar"> <li><a href="index.php?page=home">Home</a> <ul class="sub"> <li><a href="index.php?page=account">Account</a></li> <li><a href="index.php?page=profile">Profile</a></li> </ul> </li> <li><a href="index.php?page=cars">Cars</a> <ul class="sub"> <li><a href="index.php?page=smallcars">Small Cars</a></li> <li><a href="index.php?page=bigcars">Big Cars</a></li> </ul> </li> </ul> Hope this makes sense... Any help is appreciated... Hi everyone! I'm making a tab menu with HTML, CSS and JavaScript. I have this HTML: <ul class="tabmenu"> <li><a href="javascript:void(0)" onclick="tabs('1');changeActiveStates(this)" id="link1">Información</a></li> <li><a href="javascript:void(0)" onclick="tabs('2');changeActiveStates(this)" id="link2">Mapas</a></li> <li><a href="javascript:void(0)" onclick="tabs('3');changeActiveStates(this)" id="link3">Fotos</a></li> <li><a href="javascript:void(0)" onclick="tabs('4');changeActiveStates(this)" id="link4">Cómo llegar</a></li> </ul> Then I added some CSS to it (if you need to see it please tell). And the JavaScript: <script type="text/javascript"> function tbs(id){ return document.getElementById(id); } function tabsen(){ tbs("1").style.display = "none"; tbs("2").style.display = ""; tbs("3").style.display = ""; tbs("4").style.display = ""; } function tabs(id) { tabsen(); var e = tbs(id); e.style.display = ( e.style.display == '' ) ? 'block' : '' ; } function byId(id) { return document.getElementById ? document.getElementById(id) : document.all[id]; } var prevLink = ""; function changeActiveStates(ele) { if (prevLink) byId(prevLink).className = ""; ele.className = 'active'; prevLink = ele.id; } </script> The problem is: I don't know how to set active the first tab. I've tried with class='active', but when I use that atribute and click on another tab, the first one doesn't deactivate... Can anybody help me? I'm new to javascript. Can someone help me with this menu? Here is my html code: <head> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Alaska Fur Gallery</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script language="JavaScript" src="js.js"></script> <link rel="stylesheet" type="text/css" href="activemenu.css" /> <script src="jquery-activemenu.js" type="text/javascript"></script> <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.1.js"></script> <link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.1.css" media="screen" /> <script type="text/javascript"> $(document).ready(function() { $("a#fancybox").fancybox({ 'titleShow' : false, type:'image' }); //show the footer $("#footer").css("visibility","visible"); //initialize activeMenu initMenu(); }); </script> </head> <body> <div id="container"> <div id="header"> <a href="index.html"><div id="logolink">Alaska Fur Gallery</div></a> <div id="answer">We're Here to Answer Your Questions. Call Us Today at 334-277-7610</div> <div id="underlinemenu" class="ulmhead"> <ul> <li><a href="index.html" style="border:0;">Home</a></li> <li><a href="content2e96.html?id=431503">About</a></li> <li><a href="content9bf1.html?id=431504">Services</a></li> <li><a href="find_location.html">Locations</a></li> <li><a href="ct.html">Contact Us</a></li> </ul> </div> <div class="clear"></div> <div id="topmenu"> <ul id="activeMenu"> <li style="top: 0; left:0px"><a href="shopa146.html?action=cat&catID=20529" id="furs">Furs</a></li> <li style="top: 0; left:66px"><a href="shop52df.html?action=cat&catID=20541" id="leather">Leather & Fur</a></li> <li style="top: 0; left:210px"><a href="shop9e9f.html?action=cat&catID=20575" id="cashmere">Cashmere & Fur</a></li> <li style="top: 0; left:374px"><a href="shop80c4.html?action=cat&catID=21239" id="outerwear">Outerwear</a></li> <li style="top: 0; left:493px"><a href="shop0376.html?action=cat&catID=20544" id="plus">Plus Sizes</a></li> <li style="top: 0; left:604px"><a href="shop2060.html?action=cat&catID=20580" id="accessories">Accessories</a></li> </ul> </div><!-- topmenu --> </div><!-- header --> <!--submenu divs--> <div id="furs_submenu"> <ul class="dropdown" style="width:130px; float:left; margin:0 30px 0 0;"> <span>Women's Furs</span> <li><a href="shopde5e.html?action=cat&catID=20572">Mink</a></li> <li><a href="shop2705.html?action=cat&catID=20574">Sable</a></li> <li><a href="shop5c0d.html?action=cat&catID=20570">Chinchilla</a></li> <li><a href="shopdfa7.html?action=cat&catID=20568">Beaver</a></li> <li><a href="shop04fa.html?action=cat&catID=20571">Lynx</a></li> <li><a href="shop65dc.html?action=cat&catID=20569">Bobcat</a></li> <li><a href="shopc9fc.html?action=cat&catID=20622">Coyote</a></li> <li><a href="shop65f8.html?action=cat&catID=20539">Fox</a></li> <li><a href="shop3276.html?action=cat&catID=20573">Rabbit</a></li> </ul> <ul class="dropdown" style="width:140px; float:left;"> <span>Men's Furs</span> <li><a href="shop2ef6.html?action=cat&catID=20531">Mink</a></li> <li><a href="errorfe10.html?action=cat&catID=20532">Sable</a></li> <li><a href="errorfe10.html?action=cat&catID=20533">Chinchilla</a></li> <li><a href="errorfe10.html?action=cat&catID=20534">Beaver</a></li> <li><a href="errorfe10.html?action=cat&catID=20535">Lynx</a></li> <li><a href="errorfe10.html?action=cat&catID=20536">Bobcat</a></li> <li><a href="shopfc5b.html?action=cat&catID=20618">Coyote</a></li> <li><a href="shop88e4.html?action=cat&catID=20537">Fox</a></li> <li><a href="errorfe10.html?action=cat&catID=20540">Rabbit</a></li> </ul> </div> <div id="leather_submenu"> <ul class="dropdown"> <li><a href="shop973d.html?action=cat&catID=20542">Women's Leather & Fur</a></li> <li><a href="shop4cc6.html?action=cat&catID=20543" style="border:0;">Men's Leather & Fur</a></li> </ul> </div> <div id="cashmere_submenu"> <ul class="dropdown"> <li><a href="shop3f01.html?action=cat&catID=20576">Coats</a></li> <li><a href="shopd4d8.html?action=cat&catID=20577">Strollers</a></li> <li><a href="shop7899.html?action=cat&catID=20578">Jackets</a></li> <li><a href="shopcba4.html?action=cat&catID=20579" style="border:0;">Capes</a></li> </ul> </div> <div id="plus_submenu"> <ul class="dropdown" style="width:130px; float:left; margin:0 30px 16px 0;"> <span>Women's Furs</span> <li><a href="shop2530.html?action=cat&catID=20564">Mink</a></li> <li><a href="shop807e.html?action=cat&catID=20566">Sable</a></li> <li><a href="shopbc8f.html?action=cat&catID=20557">Chinchilla</a></li> <li><a href="shopcb16.html?action=cat&catID=20553">Beaver</a></li> <li><a href="shop3cb8.html?action=cat&catID=20561">Lynx</a></li> <li><a href="shopb6e3.html?action=cat&catID=20555">Bobcat</a></li> <li><a href="shop1e6c.html?action=cat&catID=20621">Coyote</a></li> <li><a href="shopc08b.html?action=cat&catID=20559">Fox</a></li> <li><a href="shop0495.html?action=cat&catID=20562">Rabbit</a></li> </ul> <ul class="dropdown" style="width:140px; float:left;"> <span>Men's Furs</span> <li><a href="shop9b23.html?action=cat&catID=20565">Mink</a></li> <li><a href="shop10dc.html?action=cat&catID=20567">Sable</a></li> <li><a href="shop8154.html?action=cat&catID=20556">Chinchilla</a></li> <li><a href="shop0b63.html?action=cat&catID=20551">Beaver</a></li> <li><a href="shopa40f.html?action=cat&catID=20560">Lynx</a></li> <li><a href="shopd843.html?action=cat&catID=20554">Bobcat</a></li> <li><a href="shopa2c0.html?action=cat&catID=20620">Coyote</a></li> <li><a href="shopb0b2.html?action=cat&catID=20558">Fox</a></li> <li><a href="shopd3b0.html?action=cat&catID=20563">Rabbit</a></li> </ul> <div class="clear"></div> <ul class="dropdown" style="width:130px; float:left; margin:0 30px 10px 0;"> <span>Leather & Fur</span> <li><a href="shop91d6.html?action=cat&catID=20549">Women's Leather & Fur</a></li> <li><a href="shop8605.html?action=cat&catID=20548">Men's Leather & Fur</a></li> </ul> <ul class="dropdown" style="width:140px; float:left; margin:-6px 0 0 0;"> <li><a href="shope478.html?action=cat&catID=20550" style="border:0;"><strong>Cashmere & Fur</strong></a></li> </ul> </div> <div id="accessories_submenu"> <ul class="dropdown"> <li><a href="shop2f26.html?action=cat&catID=20581">Fur Hats</a></li> <li><a href="shop9989.html?action=cat&catID=20582">Fur Headbands</a></li> <li><a href="shop935f.html?action=cat&catID=20583">Fur Earmuffs</a></li> <li><a href="shopd2bf.html?action=cat&catID=20584">Gloves with Fur</a></li> <li><a href="shop2c08.html?action=cat&catID=20585">Fur Boot Toppers</a></li> <li><a href="shop9f4f.html?action=cat&catID=20586">Fur Scarves & Flings</a></li> <li><a href="shop3d06.html?action=cat&catID=20587">Fur Blankets</a></li> <li><a href="shop4bf4.html?action=cat&catID=20588">Fur Handbags</a></li> <li><a href="shop611a.html?action=cat&catID=20589" style="border:0;">Mink Teddy Bears</a></li> </ul> </div> Here is the javascript: /* jQuery ActiveMenu v1.0 Author: Miguel Sanchez 12/2009 */ var timeouts = []; //for hiding the menu purposes function initMenu(){ var offclass; var menuAnchor; $("#activeMenu").find("li").each(function() { //get a reference to the anchor inside the li menuAnchor = $(this).children(":first"); //get the name of the offclass offclass = $(menuAnchor).attr("id")+"_off"; //assign off class to item $(menuAnchor).addClass(offclass); //assign hover event handler to main menu $(menuAnchor).hover( function (event) { submenu_show(event.target); }, function (event) { submenu_hide(event.target); } }); //assign hover events to submenu $("div [id$=_submenu]").hover( function (event) { submenu_over(event.target); }, function (event) { submenu_out(event.target); } } function submenu_show(caller){ //hide all the submenus $("div [id$=_submenu]").hide(); //get the id of the main menu item var mainMenuItemId = $(caller).attr("id") //get the "on" class name var onclass = mainMenuItemId+"_on"; //get the "off" class name var offclass = mainMenuItemId+"_off"; //remove off class to item $(caller).removeClass(offclass); //assign on class to item $(caller).addClass(onclass); // get the id of the submenu var targetSubMenuId = mainMenuItemId+"_submenu"; //show the submenu $("#"+targetSubMenuId).slideDown("fast"); } function submenu_hide(caller){ //get the id of the main menu item var mainMenuItemId = $(caller).attr("id"); //get the "on" class name var onclass = mainMenuItemId+"_on"; //get the "off" class name var offclass = mainMenuItemId+"_off"; //remove on class to item $(caller).removeClass(onclass); //assign off class to item $(caller).addClass(offclass); timeouts[mainMenuItemId] = setTimeout(function() { $("#"+mainMenuItemId+"_submenu").slideUp("fast"); }, 200); } function submenu_over(caller){ //get a reference to the containing div var subMenuDiv = $(caller).closest("div"); //show the div $(subMenuDiv).show(); //get the id of the main menu var mainMenuItemId = $(subMenuDiv).attr("id"); mainMenuItemId = mainMenuItemId.replace("_submenu",""); clearTimeout(timeouts[mainMenuItemId]); //remove the "off" class $("#"+mainMenuItemId).removeClass(mainMenuItemId+"_off"); //add the "on" class $("#"+mainMenuItemId).addClass(mainMenuItemId+"_on"); } function submenu_out(caller){ //get a reference to the containing div var subMenuDiv = $(caller).closest("div"); $(subMenuDiv).hide(); //get the id of the main menu var menuAnchorId = $(subMenuDiv).attr("id"); menuAnchorId = menuAnchorId.replace("_submenu",""); //remove the "on" class $("#"+menuAnchorId).removeClass(menuAnchorId+"_on"); //add the "off class $("#"+menuAnchorId).addClass(menuAnchorId+"_off"); } Here is the CSS styling: /* graphical menu codes */ #topmenu ul { list-style: none; width: 738px; height:52px; padding:0; margin: 0px; position: absolute; top:94px; right:0; overflow: hidden; } #topmenu li { display: inline; position: absolute; } #topmenu li a{ float: left; font-size:11px; line-height: 14px; white-space: nowrap; text-transform: uppercase; text-align:center; padding: 0 0 0 0; text-indent:777px; overflow:hidden; height:52px; } #topmenu li a:hover { color: #bceffa; } a.on { color: #bceffa; } #topmenu a { color: #ffffff; text-decoration: none; } #topmenu a:hover { color: #bceffa; text-decoration: none; } .furs_off { background: url("graphics/topmenu2.gif") 0 0 no-repeat; width:66px; } .furs_on { background: url("graphics/topmenu2.gif") 0 -52px no-repeat; } .leather_off { background: url("graphics/topmenu2.gif") -66px 0 no-repeat; width:144px; } .leather_on{ background: url("graphics/topmenu2.gif") -66px -52px no-repeat; } .cashmere_off { background: url("graphics/topmenu2.gif") -210px 0 no-repeat; width:165px; } .cashmere_on{ background: url("graphics/topmenu2.gif") -210px -52px no-repeat; } .outerwear_off { background: url("graphics/topmenu2.gif") -374px 0 no-repeat; width:119px; } .outerwear_on{ background: url("graphics/topmenu2.gif") -374px -52px no-repeat; } .plus_off { background: url("graphics/topmenu2.gif") -493px 0 no-repeat; width:111px; } .plus_on{ background: url("graphics/topmenu2.gif") -493px -52px no-repeat; } .accessories_off { background: url("graphics/topmenu2.gif") -604px 0 no-repeat; width:133px; } .accessories_on{ background: url("graphics/topmenu2.gif") -604px -52px no-repeat; } ul.dropdown { list-style: none; margin: 0; padding: 0; border: none; z-index:10000; position:relative; } ul.dropdown li span { display: block; _display:inline-block; text-decoration: none; } ul.dropdown li a { display: block; position: relative; _display:inline-block; /* so IE doesn't add space between elements */ _width: 83%; /* makes block fill width in IE */ padding: 6px 10px 6px 10px; font-size: 13px; color: #ffffff; text-decoration: none; border-bottom:1px solid #b78833; } ul.dropdown li a:hover{ color: #ffffff; background: #e3a73a; text-decoration: none; } .dropdown span{ font-weight:bold; color:#64450f; margin:0 0 0 10px; } #furs_submenu { width:300px; padding: 5px 0; background: #c8912f; position: absolute; top: 146px; left: 260px; display: none; z-index:1000; } #leather_submenu { width:166px; padding: 5px 0; background: #c8912f; position: absolute; top: 146px; left: 325px; display: none; z-index:1000; } #cashmere_submenu { width:192px; padding: 5px 0; background: #c8912f; position: absolute; top: 146px; left: 470px; display: none; z-index:1000; } #plus_submenu { width:300px; padding: 5px 0; background: #c8912f; position: absolute; top: 146px; left: 698px; display: none; z-index:1000; } #accessories_submenu { width:158px; padding: 5px 0; background: #c8912f; position: absolute; top: 146px; left: 840px; display: none; z-index:1000; } Hi there I've created a nav bar for this site - http://web11.3essentials.com/~cp27358/ - I'm using javascript to handle the image rollover which is working just fine. However I want to add to this so that the current page will stay with the second or rollover image. How would you suggest I edit or add to my code so it keeps the second image active if it is the active page? In my script file this is what I'm using for an image: menu1buttonup = new Image(); menu1buttonup.src = "http://web11.3essentials.com/~cp27358/wp-content/themes/origin/images/menu1.jpg" ; menu1buttondown = new Image() ; menu1buttondown.src = "http://web11.3essentials.com/~cp27358/wp-content/themes/origin/images/menu1a.jpg" ; followed by.... function buttondown( buttonname ) { if (document.images) { document[ buttonname ].src = eval( buttonname + "down.src" ); } } function buttonup ( buttonname ) { if (document.images) { document[ buttonname ].src = eval( buttonname + "up.src" ); } } and this is what my list items look like: <a href="<?php echo home_url(); ?>/?page_id=7" onmouseover="buttondown('menu1button')" onmouseout="buttonup('menu1button')"><img src="<?php bloginfo('template_url'); ?>/images/menu1.jpg" name="menu1button" /></a> thank you I'm trying to learn to write javascript myself. So please, don't right anything for me, just steer me in the right direction. The way I have my my navigation set up is when the user clicks on a section of the main nav, the subnav displays beneath the header (see the pic more a visual idea). I want the the subnav for "Services" to be displayed on all pages that are listed under Services. Same thing for everything else on the nav bar. They way it's set up right now, the "about" submenu is displayed on every page. If the user clicks on "services" then that submenu displays. Just in case you need it, I'm posting the code for that. Like I said above, please don't write anything for me, just point me in the right direction. Code: /*Javascript to display Sub Menu */ function showAbout() { if(subnav.style.display=="none") { subnav.style.display="block"; services.style.display="none"; contact.style.display="none";; partners.style.display="none"; } else subnav.style.display="none"; } function showServices() { if(services.style.display=="none"){ services.style.display="block"; subnav.style.display="none"; contact.style.display="none"; partners.style.display="none"; } else services.style.display="none"; } function showContact() { if(contact.style.display=="none"){ contact.style.display="block"; subnav.style.display="none"; services.style.display="none"; partners.style.display="none" } else contact.style.display="none"; } function showPartners() { if(partners.style.display=="none"){ partners.style.display="block"; subnav.style.display="none"; services.style.display="none"; contact.style.display="none"; } else partners.style.display="none"; } due to the version of dreamweaver i have (MX-2004) i have had to hand code a drop down menu myself however i have come across a problem. i'm not sure if the problem is in the Javascript, HTML, or CSS however here go when ever i hover over the menus dont drop down they cascade up and the other problem is that when ever i hover over one of the buttons a menu from another pops up and not the one that should. here is the codes so you can have a look javascript: Code: <script type="text/javascript"> var timeout = 500; var closetimer = 0; var ddmenuitem = 0; function mopen(id) { mcancelclosetime(); if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; ddmenuitem = document.getElementById(id); ddmenuitem.style.visibility = 'visible'; } function mclose() { if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; } function mclosetime() { closetimer = window.setTimeout(mclose, timeout); } function mcancelclosetime() { if(closetimer) { window.clearTimeout(closetimer); closetimer = null; } } document.onclick = mclose; </script> HTML code Code: <table align="center" width="950px" border="0" cellpadding="0"> <tr> <td height="50"> <div align="center"> <table width="100%" border="0" cellpadding="2" cellspacing="0"> <tr> <td width="100%" height="48" align="center" bgcolor="#CF8D72"> <ul id="sddm"><li><a href="#">Home</a></li> <li><a href="#">About Us</a></li> <!-- travel guides drop menu --> <li><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()">Guides</a> <div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="#">Africa</a> <a href="#">Asia</a> <a href="#">Australia</a> <a href="#">Europe</a> <a href="#">North America</a> <a href="#">South America</a> <a href="#">Vesas</a> <a href="#">Carnas</a> <a href="#">Driving Over Sea</a> </div> </li> <!-- adventures drop menu --> <li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">Adventures</a> <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="#">up & coming Adventures</a> <a href="#">The Team</a> <a href="#">the Journey</a> <a href="#">pod casts</a> <a href="#">Photo Gallery</a> </div> </li> <!-- travel news drop menu --> <li><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()">Travel News</a> <div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="#">Advice</a> <a href="#">Destinations</a> <a href="#">Holidays</a> <a href="#">Cities</a> <a href="#">Cruses</a> <a href="#">Hotels</a> <a href="#">Snow & skis</a> <a href="#">Expats</a> <a href="#">Watch Dog</a> </div> </li> <li><a href="#">Forum</a></li> <li><a href="#">Chatroom</a></li> <li><a href="#">Travel Shop</a></li> </ul> <div style="clear:both"></div> </td> </tr> </table> </div></td> and the CSS Code: #sddm { width: 99%; margin:'margin-top' 'margin-right' 'margin-bottom' 'margin-left' 0px font-weight: bold; z-index: 30 } #sddm li { margin: 0; padding: 0; list-style: none; float: left; font: "Baskerville Old Face", Baskerville, "Times New Roman" bold 11px; } #sddm li a { display: block; margin: 0 1px 0 0; padding: 4px 10px; width: 90px; background: url(/images/navigation/chromebg4.gif) center center repeat-x; color: #000000; text-align: center; text-decoration: none; } #sddm li a:hover { background: url(image/navigation/chromebg4-over.gif) center center repeat-x; } #sddm div { position:absolute; top: 0; border: 1px solid #E8BEBE; border-bottom-width: 0; font: "Baskerville Old Face", Baskerville, "Times New Roman" 13px; line-height:18px; z-index:100; background-color: white; width: 140px; visibility: hidden; height: 296px; } #sddm div a { position: relative; display: block; margin: 0; padding: 5px 10px; width: auto; white-space: nowrap; text-align: left; text-decoration: none; background: #EAEBD8; color: #2875DE; font: "Baskerville Old Face", Baskerville, "Times New Roman" 13px bold; } #sddm div a:hover { background-color: #FFECEC; color: #000000;} now i am making a navigation menu using images by on mouse over function, i want to make a div that shows menu using css and javascript function plz find the attached image .. and try to help me Hi - I hope someone can help me out, I've pored over this problem for hours. The site is http://www.spacemodel.com. A doctype is set. The CSS for the navmenu is: Code: #menu { background:#262626 url(images/menu_bg.gif) repeat-x top; border-bottom:1px solid #230808; margin:0 20px; height: 49px; overflow: hidden; } #menu .mleft{background: url(images/menu_side.gif) no-repeat left; width: 100%; height: 100%;} #menu .mright{background: url(images/menu_side.gif) no-repeat right; width: 100%; height: 100%;} #menu ul { width:960px; height:100%; overflow:hidden; } #menu ul li { list-style:none; font-family:Arial, sans-serif; font-weight: 700; line-height: 49px; color:#E6E6E6; font-size:11px; text-transform:uppercase; text-align:center; background:url(images/menu_side.gif) no-repeat right 0; margin:0 0 0 25px; padding: 0 25px 0 0; } #menu a:link,#menu a:visited,#menu a:active,#menu a:hover { color:#E6E6E6; text-decoration:none; } Works fine in all other browsers and versions. Affects about 5% of visitors, but one is my client All help and insight appreciated! Laurie Hi, I'm after a drop down script that basically you press categories and down it drops with say one side products by category the left side and say product by price the right side. Ign.com do it when you click on one of the top links I'm just not sure of the name and the most easiest to implement? Any help wolf be great Many thanks Joe Need some help understanding why and how to fix this.... btw this site is something I've been working on for some time..... and learning bit by bit !!! this is the site : http://www.teiafirme.com/hargrave.html this is the problem : The specific problem is that when you mouse over pictures i have a script to enlarge those pics, but my menu stays on top of those pictures !!!!!!!!!!!!! what do i need to do to fix this? If needed I will post the page html code... I also have another problem which is with the flash movie on the home page which is only loading after i navigate way from the home page and then comeback to it...... Movie does not start on initial page load !!!!! I have a navigation menu. When you mouseover, there's a sub-menu that appears. It remaining until you mouseout from the submenu or that "top level" item you mousedover in the first place. I want to change the mouseout function so it does nothing until you mousover another top-level item in the navigation. Example Shown he http://www.courage.ca Code: startList = function() { if (document.all&&document.getElementById) { navRoot = document.getElementById("nav"); for (i=0; i<navRoot.childNodes.length; i++) { node = navRoot.childNodes[i]; if (node.nodeName=="LI") { node.onmouseover=function() { this.className+=" over"; } node.onmouseout=function() { this.className=this.className.replace (" over", ""); } } } } } window.onload=startList; Hello everyone, For some reason this jQuery/JavaScript code will not show my sub menus in my navigation bar. Here is the JavaScript: Code: $(function(){ var config = { sensitivity: 3, // number = sensitivity threshold (must be 1 or higher) interval: 200, // number = milliseconds for onMouseOver polling interval over: doOpen, // function = onMouseOver callback (REQUIRED) timeout: 200, // number = milliseconds delay before onMouseOut out: doClose // function = onMouseOut callback (REQUIRED) }; function doOpen() { $(this).addClass("hover"); $('ul:first',this).css('visibility', 'visible'); } function doClose() { $(this).removeClass("hover"); $('ul:first',this).css('visibility', 'hidden'); } $("ul.pMenu li").hoverIntent(config); $("ul.pMenu li ul li:has(ul)").find("a:first").append(" » "); }); My css that corresponds to this is: Code: .pMenu{ margin:0; padding:0; } #health{ width:10%; padding-left:14%; padding-right:2%; } #insurance{ width:13%; padding-right:2%; } #shopping{ width:12%; padding-right:2%; } #dating{ width:10%; padding-right:2%; } #education{ width:13%; } ul.pMenu li{ float:left; list-style:none; } ul.pMenu li a{ display:block; color:#FFF; background:#900; border:3px ridge #C00; text-decoration:none; text-shadow:1px 1px 1px #000; white-space:nowrap; padding-left:2%; padding-right:2%; padding-top:10px; padding-bottom:10px; } ul.pMenu li a:hover{ background:#FF0; border:3px ridge #FF6; color:#FF0; } ul.pMenu li ul{ margin:0; padding:0; position:absolute; visibility:hidden; } ul.pMenu li ul li{ float:none; display:inline; } ul.pMenu li ul li a{ width:auto; background:#CCC; border:1% outset #999; font-size:95%; padding:2%; padding-left:4%; padding-right:10%; text-shadow:1px 1px 1px #000; color:#000; } ul.pMenu li ul li a:hover{ background:#999; border:1% inset #666; text-decoration:blink; } ul.pMenu li ul li ul{ margin:0; padding:0; position:absolute; visibility:hidden; } /*IE 6 & 7 need inline block feature*/ ul.pMenu ul li a{ border-right:none; width:100%; display:inline-block; } ul.pMenu li ul li ul li{ float:none; display:inline; } ul.pMenu li ul li ul li a{ width:auto; background:#999; border:1% outset #666; text-shadow:1px 1px 1px #000; color:#FFF; } ul.pMenu li ul li ul li a:hover{ background:#999; border:1% inset #666; text-decoration:blink; } ul.pMenu li ul li ul li ul{ margin:0; padding:0; position:absolute; visibility:hidden; } ul.pMenu li ul li ul li{ float:none; display:inline; } ul.pMenu li ul li ul li a{ width:auto; background:#999; border:1% outset #666; text-shadow:1px 1px 1px #000; color:#FFF; } ul.pMenu li ul li ul li a:hover{ background:#999; border:1% inset #666; text-decoration:blink; } |