0

I found a slider menu on CodePen I liked but no matter what I do I can't get the JS to run. I actually tried multiple sources of code and none worked properly.

<html>
<head>
    <title>AOS Slide</title>
    <link rel="stylesheet" type="text/css" href="slide-test.css">
    <script src="slideTest.js"></script>
</head>

<div id="button" class="button">
    <div></div>
    <div></div>
    <div></div>
  </div>
  <div id="menu" class="none">
    <nav>
      <ul>
        <li class="menu-item">
          <a href="" class="link">Home</a>
        </li>
        <li class="menu-item">
           <a href="file:///Users/scatman01/Desktop/Code/AOS3.0/AOS-hike.html">Hike</a>
        </li>
        <li class="menu-item">
          <a href="file:///Users/scatman01/Desktop/Code/AOS3.0/AOS-bike.html">Bike</a>
        </li>
        <li class="menu-item">
          <a href="file:///Users/scatman01/Desktop/Code/AOS3.0/AOS-fishing.html">Fishing</a>
        </li>
        <li class="menu-item">
          <a href="file:///Users/scatman01/Desktop/Code/AOS3.0/AOS-run.html">Run</a>
          <li role="separator" class="divider"></li>
        </li><li class="menu-item">
          <a href="file:///Users/scatman01/Desktop/Code/AOS3.0/AOS-TripleCrown.html">Triple Crown</a>
          <li role="separator" class="divider"></li>
        </li><li class="menu-item">
          <a href="file:///Users/scatman01/Desktop/Code/AOS3.0/AOS-Gallery.html">Gallery</a>
        </li><li class="menu-item">
          <a href="" class="link">Contact</a>
        </li>
      </ul>
    </nav>
  </div>
  <div id="shadow" class="none"></div>
</body>
</html>

CSS:

html {
  height: 100%; 
}

body {
  height: 100%;
  margin: 0;
  padding: .1px;
  position: relative;
  background: url(http://www.adventuresofscatman.com/wp-content/uploads/2015/09/IMG_4273.jpg);
  background-size: cover;
  overflow-x: hidden;
}

.button{
  position: absolute;
  top: 30px;
  left: 25px;;
  width: 55px;
  height: 50px;
}

.button div {
  height: 20%;
  border-top: 7px solid rgb(103, 103, 103);
  cursor: pointer;
  transition: .5s;
}

.button:hover div {
  border-color: rgb(139, 139, 139); 
}

.menu-in,
.menu-out {
  padding: .1px;
  width: 240px;
  height: 100%;
  background: rgba(0, 0, 0, .65);
  overflow: hidden;
  position: absolute;
  top: 0;
}

.menu-in {
  -webkit-animation: menu-in .9s forwards ease;
}

.menu-out{
  -webkit-animation: menu-out .4s forwards ease-in; 
}

ul {
  margin: 68px 0 0 0;
  padding: 0;
}

.menu-item {
  list-style: none;
}

.link {
  display: block;
  text-decoration: none;
  color: rgb(190, 190, 190);
  font: 28px/50px arial;
  text-transform: uppercase;
  height: 50px;
  text-align: center;
  transition: .1s;
}

.link:hover {
  color: rgb(230, 230, 230);
  background: rgba(200, 200, 200, .1); 
}

.shadow-in,
.shadow-out{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, .4);
}

.shadow-in {
  -webkit-animation: shadow-in .9s forwards ease;
}

.shadow-out {
   -webkit-animation: shadow-out .4s forwards ease-in;
}

.none {
  display: none;
}

@-webkit-keyframes menu-in {
  0% {
    left: -240px;
  }
  100% {
    left: 0;
  }
}

@-webkit-keyframes menu-out {
  0% {
    left: 0;
  }
  100% {
    left: -240px;
  }
}  

@-webkit-keyframes shadow-in {
  0% {
    left: 0;
    opacity: 0;
  }
  100% {
    left: 240px;
    opacity: 1;
  }
}

@-webkit-keyframes shadow-out {
  0% {
    left: 240px;
    opacity: 1;
  }
  99%{
    height: 100%; 
  }
  100% {
    height: 0;
    left: 0;
    opacity: 0;
  }
}

JS:

document.getElementById('button').addEventListener('click', function() {
    showMenu();
});

document.getElementById('menu').addEventListener('click', function() {
    showMenu();
});

function showMenu() {
    console.log('click');
    var menu = document.getElementById('menu');
    var shadow = document.getElementById('shadow');
    var button = document.getElementById('button');

    menu.className = 'menu-in';
    shadow.className = 'shadow-in';
    button.className = 'none';
}

document.getElementById('shadow').addEventListener('click', function() {
    var menu = document.getElementById('menu');
    var shadow = document.getElementById('shadow');
    var button = document.getElementById('button');

    menu.className = 'menu-out';
    shadow.className = 'shadow-out';
    button.className = 'button';
});
Tunaki
  • 116,530
  • 39
  • 281
  • 370
Craig
  • 1
  • 3

1 Answers1

-1

I'm quite new to Javascript myself, though I must say I ran into a similar issue like yours before. I couldn't get my external Javascript file to work. I figured out I needed a separate jQuery library hosted by Google in my .html file in order to make it work.

I am not sure which one you need (or if you need any), but can't do no harm looking up the hosted libraries by Google and paste the link between <script></script> tags just above the closing tag of your body.

A small example of my coding (might get you an idea):

<!doctype html>
<html>

<head>
  <title></title>
  <link rel="stylesheet" type="text/css" href="css/style.css">
</head>

<body>
  <div class="content">
    <div class="parallax-bg">
      <h1>Hello Everybody</h1>
    </div>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <script type="text/javascript" src="js/scrolling.js"></script>
</body>

</html>
Mr Lister
  • 42,557
  • 14
  • 95
  • 136
Manacheli
  • 9
  • 3