Problem in Creating a responsive menu

Asked

Viewed 66 times

1

Guys I’m trying to create a responsive menu but I’m in big trouble... Follow the code

I need you to keep that burger and when it reaches a certain width, show this icon by clicking on it and the menu options appear.

                <!DOCTYPE html>
                <html>
                    <head>
                        <meta charset="utf-8">
                        <meta name="viewport" content="width=device-width, initial-scale=1">
                        <meta http-equiv="X-UA-Compatible" content="IE=edge">
                        <title>dsadsadsa/dsadsadsadsa</title>
                        <link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
                        <meta name="description" content="FabMáquinas realiza conserto, manuteção e instalação de máquinas de lavar,Ar Condicionados e refrigeradores.">
                        <link rel="stylesheet" type="text/css" href="css/style.css">
                        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
                        <link href="https://fonts.googleapis.com/css?family=Roboto+Slab" rel="stylesheet">
                        <script src="http://code.jquery.com/jquery-3.3.1.js"></script>
                        <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

                    </head>
                    <body>
                        <section class="superinfo-bg">
                            <div class="texto-superinfo">
                            <h2>Segunda a Sexta - 08:00 ás 18:00 | Segunda a Sabado - 08:00 as 12:00</h2>
                            <a href="tel:1121688500"><h2>(11) 21688500</h2></a>
                            <h3>Solicite um Orçamento Grátis!</h3>
                        </div>
                        </section>
                        <nav>

                                <a href="index.html" class="logo">
                                    <img src="images/logo1.png">
                                </a>

                                <ul class="main-nav-links">
                                        <li><a href="#0">Inicio</a></li>
                                    <li><a href="#0">Serviços<i class="fa fa-chevron-down" aria-hidden="true"></i></a>
                                        <ul class="nav-dropdown">
                                            <li class="nav-dropdown">
                                                    <li><a href="#0">► Conserto de Máquina de Lavar</a></li>
                                                    <li><a href="#0">► Conserto de Máquina de Lavar</a></li>
                                                    <li><a href="#0">► Conserto de Máquina de Lavar</a></li>
                                                    <li><a href="#0">► Conserto de Máquina de Lavar</a></li>
                                                    <li><a href="#0">► Conserto de Máquina de Lavar</a></li>
                                                    <li><a href="#0">► Conserto de Máquina de Lavar</a></li>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a href="#0">Sobre</a></li>
                                    <li><a href="#0">Contato</a></li>
                                </ul>
                            </nav>
                    </body>
                </html>

css

                    html,
                    body {
                    height: 100%;
                    }

                    * {
                    margin: 0;
                    padding: 0;
                    box-sizing: border-box;
                    font-family: 'Roboto', sans-serif;
                    font-style: bold;
                    }
                    /* PADRAO PARA OS ELEMENTOS DA PÁGINAS */

                    a {
                    text-decoration: none;
                    }

                    ul {
                        list-style: none;
                    }

                    /* PADRAO 2 */


                    .superinfo-bg {
                            background-color: #1976D2;
                            width: 100%;
                            display: flex;
                            padding: 0.3%;
                            justify-content: center;
                    }

                    .texto-superinfo {
                        width: 100%;
                        display: flex;
                        justify-content: center;
                    }

                    .texto-superinfo h2 {
                        padding-right:40px;
                        font-size: 19px;
                    }

                    .texto-superinfo a {
                        color:#000;
                    }

                    .texto-superinfo a:hover {
                        color:white;
                    }

                    .text-superinfo h3 {
                        padding-right:40px;
                        font-size: 19px;
                    }

                    nav {
                        background: #bdbdbd;
                        display: flex;
                        justify-content: space-around;
                    }
                    nav ul a {
                        background: #bdbdbd;
                        display:block;
                    }

                    nav ul a:hover {
                        background:#A6A6A6;
                        border-bottom: 4px solid black;
                    }

                    nav > ul ul {
                        position: absolute;
                        visibility: hidden;
                    }

                    nav > ul {
                        display: flex;
                        justify-content: center;
                        align-items: center;
                    }

                    nav ul li:hover > ul {
                        visibility: visible;
                    } 

                    nav ul ul li {
                        position: relative;
                    }

                    nav ul ul ul {
                        position: absolute;
                        top: 0;
                        left: 100%;
                    }

                    nav ul li a {
                        color: #fff;
                        text-decoration: none;
                        text-transform: uppercase;
                        display: inline-block;
                        padding-top: 30px;
                        padding-bottom: 30px;
                        padding-right: 35px;
                        text-align: center;
                        padding-left: 35px;
                    }

                    .logo {
                        padding: 10px;
                    }

                    .logo img {
                        width: 300px;
                    }





























                    /* MEDIA QUEREIS */ 

                    @media(max-width:761px){
                        .texto-superinfo h2:nth-child(1) {
                                padding-right: 10px;
                        }

                        .texto-superinfo a  {
                            padding-right:15px;
                        }
                        .texto-superinfo h2:nth-child(2) {
                            padding-right: 10px;
                    }
                    }

                    @media(max-width:500px) {
                        .texto-superinfo {
                            display: flex;
                            flex-direction: column;
                            text-align: center;
                        }
                        .texto-superinfo h2 {
                            padding-top:8px;
                            padding-bottom: 8px;
                        }
                        .texto-superinfo h3 {
                            padding-bottom: 8px;
                            padding-top: 8px;
                        }
                    }

js

                <script type="text/javascript">
                    jQuery(function($){
                        $('.menu-btn' ).click(function(){
                            $('.responsive-menu').addClass('expand')
                            $('.menu-btn').addClass('btn-none')
                        })

                        $('.close-btn').click(function(){
                            $('.responsive-menu').removeClass('expand')
                            $('.menu-btn').removeClass('btn-none')
                        })

                    })

                    jQuery(function($){
                            $( '.menu-btn' ).click(function(){
                            $('.responsive-menu').toggleClass('expand')
                            })
                        })
                </script>

1 answer

0

I’m not the best person to answer that, but I’ll try to contribute:

You can create an Interval that will update every X time and will check the screen size, when the width reach such value, the "Burger" will appear (.show()) and the menu will disappear (.hide()) and when the screen is larger than that width the reverse will happen.

setInterval(function () {
    if(window.innerWidth <= 993){
        $("#botão").show(); //Botão aparece
        $("#Menu").hide(); //Menu some
    } else {
        $("#botão").hide(); //Botão some
        $("#Menu").show(); //Menu aparece
    }
},100);

This is a half-assed code, but I think it should help you implement in your project.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.