How to create a menu that has an effect with jquery

0

insert the image description here

I would like to know how to create a menu with jquery that when clicked opens a div like in the above example of Twitter.

    
asked by anonymous 19.07.2016 / 21:05

2 answers

1

I have not used jQuery for a long time, but I believe what you want is a Drop Down Menu Plugin, check out this link: link seems to me very simple to use, the site has examples of codes.

I hope it helps!

    
19.07.2016 / 21:33
1

You can do this feat in many ways. A simple way to do it is with JS like this:

            // nav
            $('#navbar-click').click(function() {
                if (!$('.nav').hasClass('open')) {
                    openMenu();
                } else {
                    closeMenu();
                }
            });

            function openMenu(){
                $(function(){
                    // console.log('click');
                    $('.nav').addClass('open').show(300);
                });
            }
            function closeMenu(){
                $(function(){
                    // console.log('click');
                    $('.nav').removeClass('open').hide(300);
                });
            }
            .nav{display: none;}
            ul{
                border: 2px solid #bdbdbd;
                background: #cdcdcd;
                border-radius: 2px;
                display: table;
                padding: 15px 15px;
                list-style: none;
            }
            #navbar-click{max-width: 50px;border: 3px solid #a2a2ab;border-radius: 5px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><divclass="nav-bar">
            <img id="navbar-click" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAjVBMVEUBAQP///8AAABxcXL19fX7+/vs7OzT09Pb29taWlrj4+Pr6+tdXV0pKSn///7o6Oi+vr5nZ2e0tLTIyMhCQkKfn5/Pz8/f39+Dg4OmpqasrKx7e3siIiJNTU0ICAgYGBiUlJZHR0ccHB6MjIwwMDA7OzwTExO5ubuHh4hRUVEuLi4kJCbCwsRra2t2dnh+xtZ0AAAJeElEQVR4nO3d52KjOBAAYCwDrnG3Q2zHcVxSNk7e//FOwg0QbUZlApf5t3vZoO8ANaSR06h7ONQFMB5/wurHn7D6YU04bE1Pk/k++An288lp2hraurAFoTudBJ0DS8ahE0ymrvnLGxa60/3sSnKicf3L2X7qmS2CSaE76cs0R4b2JyZvpTGhNxoX6KLK8cjYnTQk9PeHcrwb8rD3zRTFiH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g0T+ao0coW/xiA61YA85nahM4cAjyCyPDfac3e5m30NLS7r0RM7n4kwhWcJnXGSvSskSjipSy1xDnPCR/qRmCGnzP2Iic8NJhpA0rQAuspIRpAsJtsSoR8aOjFSh7WNy9ETGKsY0YfVewnOkv4ppQuJUUPhITWieIiTOwaoQ8lf3VCFtih21YEz+RicLK/uMikjZDC0JiTNdKUbKpEZSWOVnVIScWCIprGRbHwkmtfsJId35I7pCmtNICCvYH01Gsn8aF75XHyglsYkJ7e4LNRWJ/aYxYXV7M7GI92yiQtp0evoinpgvKnyqBzDRPY0IbR2zbT7Yl5sqJD71QGdEV9rdhZTnOOmOaN/tLqxJRXqOyIfTu7AWbeE1InuHb8JadGfucc8pdRMS51rXHffM5lfhY72AnPiYEFZ9XCjFbZx4EfoZC3KrG+zFjwmrPTuTGtcZG6eW9YyIa6LMs9B21icbcc0sdRbWZVQRi0u/5iyswfSMHJcJm1BY/Rm2tLjMuoVC4jMrTMV5DBUKic//MRXnIz2F0K0n8DJKFELiYynNRTjAEMJKrX6CRJh3ggvdyqzQgwZbu6Gwnm2FiLC9cGrbVogQ7YVT8c/a+SEWZzgNrzYTwXKwtceFVV0fVCbE+MKpb2sogr1zYcWWysKCBVxYy5HTNfgIyvFqNwcVDfbmOXWuaMLlis6pzkAuPDk1nEeMBls6tZvsjgdbOTWcKY0Ge3VqXZWKyX2nJitMsoJtnNoOf8/B1o6p5KO/JNjYIT4b1nSwqdOo0DZDeLBn3vP2d/Ulis+kzqAxPOjcWv17gqsOwwYXDhqN+Tozk1OV42veaAwGobDhLeZBs14RzBdiIe1AY4bW3xp/wurHn7D6UX/hf+I5mfuyG2FHAAAAAElFTkSuQmCC" alt="">
        </div>
        <div class="nav">
            <i class="fa fa-times" aria-hidden="true" id="navbar-close"></i>
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="portfolio.html">Portfólio</a></li>
                <li><a href="blog">Blog</a></li>
            </ul>
        </div>

I hope I have helped.

    
19.07.2016 / 21:16