Я хочу скрыть и показать панель навигации той же кнопкой. Я скопировал несколько фрагментов кода вокруг интернета и сумел обойти навигацию с помощью настраиваемой анимированной кнопки, но все еще есть специальная кнопка закрытия. Как мне сопоставить функцию закрытия с той же кнопкой, которая открывает навигацию
спасибо
PS: если вы можете сказать мне, что изменить, чтобы навигация происходила справа, а не слева буду очень признателен
/*bar animation bar to cross*/
function myFunction(x) {
x.classList.toggle("change");
}
/* Set the width of the side navigation to 250px */
function openNav() {
document.getElementById("mySidenav").style.width = "500px";
}
/* Set the width of the side navigation to 0 */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
/* Header */
/* Style the header with a grey background and some padding */
.header {
overflow: hidden;
background-color: #FFFFFF;
padding-top: 40px;
padding-right: 10px;
padding-left: 10px;
padding-bottom: 50px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.2);
}
/* Style the header links */
.header a {
float: left;
color: black;
text-align: center;
padding-top: 12px;
padding-right: 12px;
padding-left: 12px;
padding-bottom: 12px;
text-decoration: none;
font-family: lato;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.menu_bar_icon {
display: inline-block;
cursor: pointer;
}
.bar1,
.bar2,
.bar3 {
width: 20px;
height: 2px;
background-color: #000000;
margin: 4px 0;
transition: 0.4s;
}
/* Rotate first bar */
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-4px, 3px);
transform: rotate(-45deg) translate(-4px, 3px);
}
/* Fade out the second bar */
.change .bar2 {
opacity: 0;
}
/* Rotate last bar */
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-5px, -4px);
transform: rotate(45deg) translate(-5px, -4px);
}
/* The side navigation menu */
.sidenav {
height: 90px;
/* 100% Full-height */
width: 0;
/* 0 width - change this with JavaScript */
position: fixed;
/* Stay in place */
z-index: 1;
/* Stay on top */
top: 0;
/* Stay at the top */
left: 70%;
overflow-x: hidden;
/* Disable horizontal scroll */
padding-top: 50px;
/* Place content 60px from the top */
transition: 0.5s;
/* 0.5 second transition effect to slide in the sidenav */
}
/* The navigation menu links */
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 15px;
color: #000000;
display: block;
transition: 0.3s;
}
/* When you mouse over the navigation links, change their color */
.sidenav a:hover {
color: #E20105;
}
/* Position and style the close button (top right corner) */
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
transition: margin-left .5s;
padding: 20px;
}
/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
.sidenav {
padding-top: 15px;
}
.sidenav a {
font-size: 18px;
}
}
/* Style the logo link (notice that we set the same value of line-height and font-size to prevent the header to increase when the font gets bigger */
.header a.logo {
font-size: 130px;
font-weight: bold;
}
/* Change the background color on mouse-over */
.header a:hover {
background-color: #ddd;
color: black;
}
/* Style the active/current link*/
.header a.active {
background-color: dodgerblue;
color: white;
}
/* Float the link section to the right */
.header-right {
float: right;
}
/* Add media queries for responsiveness - when the screen is 500px wide or less, stack the links on top of each other */
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
#container {
width: 100%;
/* Your width */
height: 100%;
/* Your height */
display: flex;
justify-content: center;
/* This will center container with items horizontally */
align-items: center;
/* This will center container with items vertically */
/* outline: 5px dashed yellow;
*/
}
<link href="http://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet" type="text/css">
<div class="header">
<a href="#default" class="logo">Kunden;</a>
<div class="header-right">
<div class="menu_bar_icon" onclick="myFunction(this), openNav()">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
</div>