1

After a lot of work and a whole bunch of searching and combining code, I finally got my lava lamp drop down menu navigation to work (Look here: http://lookseewatch.com/overflowexample/menu.html). Great.

Here's the problem: I cannot for the life of me get it work with Wordpress menus (wp_nav_menu). I have been unable to get wp_nav_menu to generate the same markup as my current hard code. I also need to have this <div id="box"><div class="head"></div></div> INSIDE of "<ul class="nav">." wp_nav_menu does not allow me to do this because it generates the containing ul class and so on.

So after a few hours of trying different things, I just can't get it. If you go here http://lookseewatch.com/independentinsurance/ you'll see two navigations space by about 300 pixels. The first, is the hard-coded version, the second is generate by wp_nav_menu. I've changed the css to work with the second navigation, so the top is a little funny, but you will notice that the "magic line" follows both version of the navigation, which I thought was interesting. I just don't know how to get it below the dynamic version. The second problem is, when you hover over "Insurance Services" on the second navigation, all is fine, you then hover over "Commercial Insurance" and 3 new drop downs appear, when you go to hover or click one of these options, they quickly disappear. I have no idea why.

Here's the code for my navigation.js

var speed = 400;//speed of lava lamp
var menuFadeIn = 0;//speed of menu fade in transition
var menuFadeOut = 0;//speed of menu fade in transition
var style = 'easeOutQuart';//style of lava lamp
var totalWidth = 0;//variable for calculating total width of menu according to how many li's there are
var reducedWidth = 4;
(function($) {  
$(document).ready(function(){

    if($.browser.opera){
        $(".nav ul").css("margin-top", "32px");//opera fix for margin top
        $(".nav ul ul").css("margin-top", "-20px");
    }
    if(!$.browser.msie){// ie fix
        $("ul.nav span").css("opacity", "0");
        $(".nav ul ul ul").css("margin-top", "-20px");
    }
    if($.browser.msie){
        $("ul.nav span").css({visibility:"hidden"});
    }
       //totalWidth = $(".nav li:last").offset().left -  $(".nav li:first").offset().left + $(".nav li:last").width();//width of menu
       //$(".nav").css({width:totalWidth});//setting total width of menu

       var dLeft = $('.current-menu-item a').offset().left+15;//setting default position of menu
       var dWidth = $('.current-menu-item a').width();
       var dTop = $('.current-menu-item a').offset().top;

       //var origLeft = .data($dLeft.offset().left+14);
       //var origWidth = .data($dWidth.width());
       //var origTop = .data($dTop.offset().top);

        //Set the initial lava lamp position and width
        $('#box').css({left:dLeft});
        $('#box').css({top: dTop});
        $('#box').css({width: dWidth});



    $(".nav > li").hover(function(){
        var position = $(this).offset().left+15;//set width and position of lava lamp
        var width = $(this).width()-29; 
        if(!$.browser.msie){//hover effect of triangle (glow)
            $(this).find('span:first').stop().animate({opacity: 1}, 'slow');
        }
        else{
            $(this).find('span:first').css({visibility:"visible"}); 
        }
        $('#box').stop().animate({left:position, width:width},{duration:speed, easing: style});
        }, function() {
            $('#box').stop().animate({left:dLeft, width:dWidth},{duration:speed, easing: style});
        },

        function(){
        if(!$.browser.msie){
            $(this).find('span:first').stop().animate({opacity: 0}, 'slow');//hiding the glow on mouseout
        }

        if($.browser.msie){
            $(this).find('span:first').css({visibility:"hidden"});      
        }           
    });



    $(".nav li").hover(function(){//animating the fade in and fade out of submenus level 1
           $(this).find('li').fadeIn(menuFadeIn); 
            $('li li li').css({display:"none"});
            },
           function(){  
                $(this).find('li').fadeOut(menuFadeIn); 
           });  

             $(".submenu0 li").hover(function(){//animating the fade in and fade out of submenus level 2 
                $(this).find('li').fadeIn(menuFadeIn);  
                $('li li li li').css({display:"none"});

            },
            function(){  
                $(this).find('li').fadeOut(menuFadeOut); 

            }); 
             $(".submenu1 li").hover(function(){//animating the fade in and fade out of submenus  level 3
            $(this).find('li').fadeIn(menuFadeIn);  
            },
            function(){  
                $(this).find('li').fadeOut(menuFadeOut); 


            }); 


});

})($);

I think the problem lies in this area with how I am targeting the second or third level.

         $(".submenu0 li").hover(function(){//animating the fade in and fade out of submenus level 2 
            $(this).find('li').fadeIn(menuFadeIn);  
            $('li li li li').css({display:"none"});

        },
        function(){  
            $(this).find('li').fadeOut(menuFadeOut); 

        }); 
         $(".submenu1 li").hover(function(){//animating the fade in and fade out of submenus  level 3
        $(this).find('li').fadeIn(menuFadeIn);  
        },
        function(){  
            $(this).find('li').fadeOut(menuFadeOut); 


        }); 

Anyways, I appreciate the help. I need to figure out a work around for this, so if you have any suggestion please feel free to speak them. Also, if I need to provide any code snippets, I happily will. Anything to solve this navigation.

  • In your `.nav ul {` you should change the `margin-top` to `14px`. Right now when you scroll slowly from the top into the menu and the drop down opens. Continue scrolling slowly to the drop down slowly it will get closed before you're on the drop down itself. – bart s Dec 07 '12 at 11:52

1 Answers1

0

Ok so what you need is found in the Wordpress Codex. In the array of defaults for the wp_nav_menu() function (found here) you can see there's an option called items_wrap. Using this we can add your divs to the end of the menu:

<?php wp_nav_menu( array('items_wrap' => '<ul class="%2$s">%3$s<div id="box"><div class="head"></div></div></ul>' ) ); ?>

--- EDIT ---

Ok what seems to be the issue with your submenu hover is this line:

$('li li li').css({display:"none"});

I took the liberty of creating a jsFiddle with your issue here: http://jsfiddle.net/zAqct/ As you can see the line in question is commented out and the hover seems to be working again. Obviously this isn't quite 100% so I have produced a simpler test case.

--- 2nd EDIT ---

Ok so on a further look I think the main issue is your CSS and JS is proving to be a little over complicated. To illustrate a simpler method I've updated the jsFiddle here: http://jsfiddle.net/zAqct/2/

You should find this version works more the way you need it to.

Steve O
  • 5,224
  • 1
  • 24
  • 26
  • Thanks for your response, that solved half of my problem. The other is the drop down menu. When I over the 2nd level, it disappears unexplained. What can I provide to help you help me solve this? Thanks again. – Henry Bayuzick Dec 06 '12 at 15:59
  • In your navigation.js file you may want to try using `mouseenter` and `mouseleave` instead of a `hover` function. If that doesn't solve it, post your js in your question and we can check it over in more detail. – Steve O Dec 06 '12 at 18:54
  • I tried that, but it made it worse. I have posted my Jquery for you to look at. Thanks for the help. – Henry Bayuzick Dec 06 '12 at 22:59
  • Ok I've added an edit above and created you a jsFiddle here: http://jsfiddle.net/zAqct/ – Steve O Dec 07 '12 at 11:47
  • So the pevious edit was not 100% so I've created a simplified version for you here: http://jsfiddle.net/zAqct/2/ See the second edit above. – Steve O Dec 07 '12 at 12:19
  • That did, thank you so much! I have another problem, but it's a little different from the original question. When you do go and hover over the links, their drop downs fall under the slideshow I have on the website. I have tried some z-index stuff, but because it's in a grid and floated, that doesn't really work. Any suggestions? Thanks again! – Henry Bayuzick Dec 07 '12 at 14:51
  • No problem. If you can accept the answer that'd be great. As far as your z-index issue, you'll need to make sure your elements are `relative` or `absolute` positioned for your z-index's to work. Best thing is to open up a new question and you should get a quick answer :) – Steve O Dec 07 '12 at 15:14