Oam Psy
Oam Psy

Reputation: 8663

Creating A Dropline Style Menu

I am trying to create a dropline style menu.

Please see my fiddle here - http://jsfiddle.net/oampz/38c6q/

The issue i'm having is, i don't want the brown menu - or for it to drop down/fade in.. I'm trying to get the sub menu items to simply appear in the grey coloured sub DIV.

$('#main-nav > li').hover(function(){
            if(!$(this).find('.main-link').hasClass('active')){
                $("#main-nav > li a.active").removeClass("active");
                $(this).find('.main-link').addClass("active");
                if($(this).find('li').length){
                    //$("#main-nav li a.close").stop().fadeIn();
                    //There is no .close
                    var that = this;
                    $("#sub-link-bar").stop().animate({ height: "40px"}, function(){
                        $(that).find(".sub-links").show();
                    });
                }
                else {
                     $(this).find(".sub-links").stop().fadeOut( function(){
                        $(this).css('opacity','1');
                        $("#sub-link-bar").stop().animate({height: "1px"});
                     });
                }
            }
        }, function(){
            if($(this).find('li').length){
                $(this).find(".sub-links").stop().hide( function(){
                    $(this).css('opacity','1');

                });
            }
            $("#sub-link-bar").stop().animate({height: "1px"});
           $(this).find('.main-link').removeClass('active');
        });

Any help appreciated.

Upvotes: 0

Views: 333

Answers (1)

Michael B.
Michael B.

Reputation: 2809

I've updated the code http://jsfiddle.net/38c6q/1/

replaced this

$("#sub-link-bar").stop().animate({ height: "40px"}, function(){
    $(that).find(".sub-links").show();
});

with

 $('#sub-menu').html(  $(that).find(".sub-links").html() )

To have them float next to each other, you can add this CSS

.sub-menu li{
    display:block;
    padding:0;
    margin:0;
    float:left;
}

And to add some colors and backgrounds to links, add some CSS like this

.sub-menu a{
    display:block;
    margin:0 5px;
    padding:5px;
    text-decoration:none;
    Color:#333;
}

.sub-menu a:hover{
    background:#333;
    color:#fff;
}

updated Demo at http://jsfiddle.net/38c6q/4/

Upvotes: 1

Related Questions