Crkva Kovacica Crkva Kovacica - 4 months ago 9
Javascript Question

How can this menu be fixed so it can be responsive?

I have this menu: (the snippet is quite long), please look at the snippet in fullscreen...



$(document).ready(function() {
$('.burger').click(function() {
$(this).toggleClass('open');
$('.header_menu').toggleClass('is_open');
$('span').toggleClass('close');
$('#menu').toggleClass('menu_open');
});
});

@import url(https://fonts.googleapis.com/css?family=Raleway:400,200,300,800,900,800italic,700);
@import url(https://fonts.googleapis.com/css?family=Lobster);
@import url(https://fonts.googleapis.com/css?family=Montserrat:400,700);
::selection {
background: transparent;
color: #999;
}
body {
margin: 0;
padding: 0;
}
::-scrollbar {
display: none;
}
* {
box-sizing: border-box;
}
#header_wrapper {
width: 100%;
position: fixed;
}
#header {
width: 80%;
margin: 1rem auto;
position: relative;
display: flex;
justify-content: space-between;
}
.header_logo {
margin: 0;
left: 0;
display: inline-block;
font-family: "Raleway";
font-weight: bold;
color: #ffffff;
background-color: #111;
padding: .2em;
font-size: 40px;
}
.header_logo::-moz-selection {
background: transparent;
}
.header_logo a {
text-decoration: none;
color: white;
}
.header_logo::-o-selection {
background: transparent;
}
.header_logo::-webkit-selection {
background: transparent;
}
.header_logo::selection {
background: transparent;
}
.burger {
border: 0;
position: absolute;
right: 0;
background: none;
outline: 0;
padding: 0;
cursor: pointer;
border-bottom: 5px solid currentColor;
width: 40px;
top: 39%;
transform: translateX(-50%);
}
.burger::-moz-focus-inner {
border: 0;
padding: 0;
}
.burger:before {
content: "";
display: block;
border-bottom: 5px solid currentColor;
width: 100%;
margin-bottom: 5px;
transition: 0ms;
transition-delay: 1500ms;
}
.burger:after {
content: "";
display: block;
margin-bottom: 5px;
border-bottom: 5px solid currentColor;
width: 100%;
transition: 0ms;
transition-delay: 1500ms;
}
.burger.open {
border-bottom: none;
transition: border-bottom 0.8s ease-in-out;
-webkit-transition: border-bottom 0.8s ease-in-out;
}
.burger.open:before {
border-bottom: 5px solid #fff;
transform: rotate(-405deg) translateY(1px) translateX(-3px);
-webkit-transform: rotate(-405deg) translateY(1px) translateX(-3px);
transition: transform 0.5s ease-in-out;
transform-origin: center;
-webkit-transition: -webkit-transform 0.5s ease-in-out;
}
.burger.open:after {
border-bottom: 5px solid #fff;
transform: rotate(405deg) translateY(-4px) translateX(-5px);
-webkit-transform: rotate(405deg) translateY(-4px) translateX(-5px);
transition: transform 0.5s ease-in-out;
transform-origin: center;
-webkit-transition: -webkit-transform 0.5s ease-in-out;
}
.header_menu {
width: 90%;
position: absolute;
background: #000;
top: 0;
right: 0;
left: 100%;
height: 100%;
pointer-events: none;
transition: transform 300ms ease-in-out;
transition-delay: 1200ms;
}
.header_menu.is_open {
transform: translateX(-100%);
pointer-events: auto;
transition: transform 300ms ease-in-out;
transition-delay: 400ms;
}
span {
position: absolute;
top: 50%;
left: 2%;
display: block;
color: #fff;
font-family: "Raleway";
font-weight: bold;
transform: translateY(-50%);
transition: all 300ms ease-in;
transition-delay: 1400ms;
}
span.close {
opacity: 0;
transition: all 300ms ease-in;
}
#menu {
width: 100%;
text-align: center;
padding: 0;
margin: 0;
position: absolute;
top: 50%;
left: 100%;
transform: translateY(-50%);
text-decoration: none;
transition: transform 1000ms ease-in-out;
transition-delay: 400ms;
}
#menu.menu_open {
transform: translateX(-100%) translateY(-50%);
transition: transform 400ms ease-in-out;
transition-delay: 600ms;
background-color: transparent;
}
#menu li {
list-style: none;
display: inline-block;
margin-left: 1em;
z-index: 99999;
}
#menu li a {
text-decoration: none;
color: white;
font-family: "Raleway";
text-transform: uppercase;
font-weight: bold;
z-index: 99999;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="header_wrapper">
<div id="header">
<div class="header_logo">
<a href="/about_me">JD</a>
</div>

<div class="header_menu">
<span>MENU</span>
<ul id="menu">
<li><a href="/home">Home</a>
</li>
<li><a href="#">About me</a>
</li>
<li><a href="#">Work</a>
</li>
<li><a href="#">Tools</a>
</li>
<li><a href="#">Blog</a>
</li>
<li><a href="#">Contact</a>
</li>
<li><a href="#">Services</a>
</li>
</ul>
</div>

<div class="burger">
</div>
</div>
</div>





It looks nice, but the problem is the smaller screens, it covers the logo and burger, i had an idea for smaller screens to be like this:

enter image description here

but i don't know how to achieve this, maybe i have some mistakes in code, or my concept is wrong.... Please help.

Answer

$(document).ready(function() {
  $('.burger').click(function() {
    $(this).toggleClass('open');
    $('.header_menu').toggleClass('is_open');
    $('.header_menu').toggleClass('hidden');
    $('span').toggleClass('close');
    $('#menu').toggleClass('menu_open');
  });
});
@import url(https://fonts.googleapis.com/css?family=Raleway:400,200,300,800,900,800italic,700);
@import url(https://fonts.googleapis.com/css?family=Lobster);
@import url(https://fonts.googleapis.com/css?family=Montserrat:400,700);
::selection {
  background: transparent;
  color: #999;
}
body {
  margin: 0;
  padding: 0;
}
::-scrollbar {
  display: none;
}
* {
  box-sizing: border-box;
}
#header_wrapper {
  width: 100%;
  position: fixed;
}
#header {
  width: 80%;
  margin: 1rem auto;
  position: relative;
  display: flex;
  justify-content: space-between;
}
.header_logo {
  margin: 0;
  left: 0;
  display: inline-block;
  font-family: "Raleway";
  font-weight: bold;
  color: #ffffff;
  background-color: #111;
  padding: .2em;
  font-size: 40px;
}
.header_logo::-moz-selection {
  background: transparent;
}
.header_logo a {
  text-decoration: none;
  color: white;
}
.header_logo::-o-selection {
  background: transparent;
}
.header_logo::-webkit-selection {
  background: transparent;
}
.header_logo::selection {
  background: transparent;
}
.burger {
  border: 0;
  position: absolute;
  right: 0;
  background: none;
  outline: 0;
  padding: 0;
  cursor: pointer;
  border-bottom: 5px solid currentColor;
  width: 40px;
  top: 39%;
  transform: translateX(-50%);
}
.burger::-moz-focus-inner {
  border: 0;
  padding: 0;
}
.burger:before {
  content: "";
  display: block;
  border-bottom: 5px solid currentColor;
  width: 100%;
  margin-bottom: 5px;
  transition: 0ms;
  transition-delay: 1500ms;
}
.burger:after {
  content: "";
  display: block;
  margin-bottom: 5px;
  border-bottom: 5px solid currentColor;
  width: 100%;
  transition: 0ms;
  transition-delay: 1500ms;
}
.burger.open {
  border-bottom: none;
  transition: border-bottom 0.8s ease-in-out;
  -webkit-transition: border-bottom 0.8s ease-in-out;
}
.burger.open:before {
  border-bottom: 5px solid #fff;
  transform: rotate(-405deg) translateY(1px) translateX(-3px);
  -webkit-transform: rotate(-405deg) translateY(1px) translateX(-3px);
  transition: transform 0.5s ease-in-out;
  transform-origin: center;
  -webkit-transition: -webkit-transform 0.5s ease-in-out;
}
.burger.open:after {
  border-bottom: 5px solid #fff;
  transform: rotate(405deg) translateY(-4px) translateX(-5px);
  -webkit-transform: rotate(405deg) translateY(-4px) translateX(-5px);
  transition: transform 0.5s ease-in-out;
  transform-origin: center;
  -webkit-transition: -webkit-transform 0.5s ease-in-out;
}
.header_menu {
  width: 90%;
  position: absolute;
  background: #000;
  top: 0;
  right: 0;
  left: 100%;
  height: 100%;
  pointer-events: none;
  transition: transform 300ms ease-in-out;
  transition-delay: 1200ms;
}
.header_menu.is_open {
  transform: translateX(-100%);
  pointer-events: auto;
  transition: transform 300ms ease-in-out;
  transition-delay: 400ms;
}
span {
  position: absolute;
  top: 50%;
  left: 2%;
  display: block;
  color: #fff;
  font-family: "Raleway";
  font-weight: bold;
  transform: translateY(-50%);
  transition: all 300ms ease-in;
  transition-delay: 1400ms;
}
span.close {
  opacity: 0;
  transition: all 300ms ease-in;
}
#menu {
  width: 100%;
  text-align: center;
  padding: 0;
  margin: 0;
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  text-decoration: none;
  transition: transform 1000ms ease-in-out;
  transition-delay: 400ms;
}
#menu.menu_open {
  transform: translateX(-100%) translateY(-50%);
  transition: transform 400ms ease-in-out;
  transition-delay: 600ms;
  background-color: transparent;
}
#menu li {
  list-style: none;
  display: inline-block;
  margin-left: 1em;
  z-index: 99999;
}
#menu li a {
  text-decoration: none;
  color: white;
  font-family: "Raleway";
  text-transform: uppercase;
  font-weight: bold;
  z-index: 99999;
}
@media (max-width: 700px) {
 .hidden {
  display: none;
 }
 .header_menu {
   min-height: 200px;    
   width: 100%;
   top: 64px;
 }
 .burger {
   background-color: #000;
 }
 #menu li {
   display: block;
 }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="header_wrapper">
  <div id="header">
    <div class="header_logo">
      <a href="/about_me">JD</a> 
    </div>

    <div class="header_menu hidden">
      <span>MENU</span> 
      <ul id="menu">
        <li><a href="/home">Home</a>
        </li>
        <li><a href="#">About me</a>
        </li>
        <li><a href="#">Work</a>
        </li>
        <li><a href="#">Tools</a>
        </li>
        <li><a href="#">Blog</a>
        </li>
        <li><a href="#">Contact</a>
        </li>
        <li><a href="#">Services</a>
        </li>
      </ul>
    </div>

    <div class="burger">
    </div>
  </div>
</div>