0

I try to do a dropdown menu on click. I tried to toggle two classes when i click on the "Menu" and transition between 0 max-height and 20 em max-height on my navbar. But as I see when i have 0 max-height it's taking a white space like a placeholder. i dont want that because it messes my aspect of the website . I was thinking at display:block and display:none but i know you can't transitione between these two . Is there any way to create a dropdown menu on click when i click on a specified place ? EDIT :

i have this code:

html :

<header>
<nav>
<div class="handle">Menu</div>
<ul>
<li><a id="active" href="index.html">HOME</a></li>
<li><a href="collection.html">PRODUCTS</a></li>
<li><a href="events.html">EVENTS</a></li>
<li><a href="info.html">CONTACT</a></li>
</ul>
</nav>
</header>

and css:

.handle{
    width: 100%;
    background:#333333;
    text-align: left;
    box-sizing: border-box;
    padding:15px 10px;
    cursor: pointer;
    display: none;
    color: white;
    box-sizing: border-box;
}

@media (max-width:980px){

    .showing{
        max-height:20em ;
    } 
 nav ul{
        max-height: 0;

    }
}

and the JS :

$(document).ready(function () {
$('.handle').on('click', function () {
 $('nav ul').toggleClass('showing')
});
});

There is some more styling to the header but i think is not important.Sorry if i was unclear .

2
  • Can't understand a "this".str_rev();! Commented Aug 13, 2015 at 21:37
  • 1
    Please create Jsfiddle or share code in some way. so that we can help you better. Commented Aug 13, 2015 at 21:41

1 Answer 1

1

this code works for me. hope will help ...

  <!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>On click Menu</title>
        <style>
            .handle{
                width: 100%;
                background:#333333;
                text-align: left;
                box-sizing: border-box;
                padding:15px 10px;
                cursor: pointer;
                color: white;
                box-sizing: border-box;
            }

            .hide {
                display: none;
            }
        </style>
    </head>
    <body>
        <nav>
            <div class="handle">Menu</div>
            <ul class="hide">
                <li><a id="active" href="index.html">HOME</a></li>
                <li><a href="collection.html">PRODUCTS</a></li>
                <li><a href="events.html">EVENTS</a></li>
                <li><a href="info.html">CONTACT</a></li>
            </ul>
        </nav>

        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script>

            $(document).ready(function() {
                $('.handle').on('click', function() {
                    $('nav ul').slideToggle();
                });
            });

        </script>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

Yes it works but i want a tranisition between hide and show the menu
I have updated the code. just use slideToggle function for tranisition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.