-3

Trying to do a responsive sliding animation for a navbar/menu using logos like lines and an X logo and when i click the logo nothing happens , when I debug it this error appears index.html:27 Uncaught ReferenceError: showMenu is not defined any ideas what i can change

Menu Logos only appears when viewing the page in the device toolbar

var navLinks=document.getElementById("navLink")

function hideMenu(){
    navLinks.style.right= "-200px";
}
function showMenu() {
    navLinks.style.right = "0";
}
*{
margin:0;
padding:0;
font-family: 'Roboto', sans-serif;
}
.header{
    min-height: 100vh;
    width: 100%;
    background-color: transparent);
    background-image: linear-gradient(rgb(94, 94, 94),#00203FFF);
    background-position: center;
    background-size: cover;
    position: relative;
}
nav{
    display: flex;
    padding: 2% 6%;
    justify-content: space-between;
    align-items: center;
}
nav img{
    width: 300px;
}
.nav-links{
    flex: 1;
    text-align: right;
}
.nav-links ul li{
    list-style: none;
    display: inline-block;
    padding: 8px 12px;
    position: relative;
}
.nav-links ul li a{
    color: white;
    text-decoration: none;
    font-size: 25px;
}
.nav-links ul li::after{
    content: '';
    width: 0%;
    height: 2px;
    background: #00203FFF;
    display: block;
    margin: auto; 
    transition: 0.5s;   
}
.nav-links ul li:hover::after{
    width: 100%;
}
.text-box{
    width: 90%;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    text-align: center;
    background-color:transparent;
}
.text-box h1{
    font-size: 62px
}
.text-box p{
    margin: 10px 0 40px;
    font-size: 14px;
    color: white;
}
.btn{
    display: inline-block;
    text-decoration: none;
    color: white;
    border: 1px solid #fff;
    padding: 12px 34px;
    font-size: 13px;
    background: transparent;
    position: relative;
    cursor: pointer;
}
.btn:hover{
    border: 1px solid rgb(94, 94, 94);
    background: rgb(94, 94, 94);
    transition: 1s;
}
nav .fas{
    display:none;
}

@media(max-width: 700px){
    .text-box h1{
        font-size: 20px;
    }
    .nav-links ul li{
        display: block;
    }
    .nav-links{
        position: absolute;
        background: #2A2B2DFF;
        height: 100vh;
        width: 200px;
        top: 0;
        right: -200%;
        text-align: left;
        z-index: 2;
        transition: 1s;
    }
    nav .fas{
        display: block;
        color:black;
        margin: 15px;
        font-size: 25px;
        cursor: pointer;
    }
    .nav-links ul{
        padding: 27px;
    }
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="with=device-width, initial-scale=1.0">
    <title>St.Louis School Inc.</title>
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
    <script type="text/javascript" href="menu.js"></script>   
</head>
<body>
<section class="header">
        <nav>
                <a href="index.html"><img src="images/logo.png"> </a>
                <div class="nav-links" id="navLink">
                <i class="fas fa-times" onclick="hideMenu(hide)"> </i>
                <ul> 
                <li><a href="">HOME</a></li>
                <li><a href="">ABOUT US</a></li>
                <li><a href="">VISION & MISSION</a></li>
                <li><a href="">HISTORY</a></li>
                <li><a href="">Facilities</a></li>
                <li><a href="">CONTACT US</a></li>
                </ul>
                </div>
                <i class="fas fa-bars" onclick="showMenu(show)"></i>> </i>
            </nav>
<div class="text-box">
  <h1>Saint Louis University Inc.</h1>
   <p>etcetcetcetc</p>
    <a href="" class="btn">Click here to explore</a>
   </div>
</section>





</body>
</html>
Element
  • 1
  • 2
  • In this case, `show` is not defined. `showMenu` does not accept arguments anyway, so remove it. If `showMenu` is not defined, then the dev tools provide a **Network** tab for that. Please confirm: Is the resource `menu.js` _found_ (e.g. HTTP 200 response)? If not, which _actual URL_ is requested? Please see [Why does jQuery or a DOM method such as getElementById not find the element?](/q/14028959/4642212) to fix another bug. `navLinks` will be `null`, otherwise. – Sebastian Simon May 02 '21 at 23:12
  • Inline event handlers like `onclick` are [not recommended](https://stackoverflow.com/q/11737873/4642212). They are an [obsolete, hard-to-maintain and unintuitive](https://stackoverflow.com/a/43459991/4642212) way of registering events. Always [use `addEventListener`](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_%E2%80%94_dont_use_these) instead. – Sebastian Simon May 02 '21 at 23:16
  • 1
    Your menu file isn’t loading because you’re using `href` in the link – use `src ="menu.js"` – your `onclick` attributes aren’t working because you’re passing `show` and `hide` as variables – you need to pass them as text strings `onclick="showMenu('show')"` but @Sebastian is correct – you should use a listener. Also, there’s an extra close-parenthesis after `transparent` in your styles, and you’re lacking a `` tag and it’s good to have `shrink-to-fit=no` in your viewport meta tag. – Rich DeBourke May 02 '21 at 23:30

0 Answers0