打开汉堡包菜单

时间:2018-05-26 12:20:36

标签: javascript html css hamburger-menu

任何人都可以帮我制作“汉堡菜单”吗?我想要的是,当一个人点击它时,旁边会出现“Home and Works”等字样。然后当你关闭它并转到它之前的形式时,菜单也会消失。

HTML

<div class="container" onclick="myFunction(this)">
  <div class="bar1"></div>
  <div class="bar2"></div>
  <div class="bar3"></div>
  <div class="bar4"></div>
  <div class="bar6"></div>
  <div class="bar5"></div>
</div>

CSS

<style>

.container {
  display: inline-block;
  cursor: pointer;
  position: absolute;
  top: 50px;
  right: 50px;
  z-index: 99
}


.bar1{
  width: 48px;
  height: 5px;
  background-color: rgb(156, 156, 156);
  margin: 6px 0;
  transition: 0.4s;
}

.bar2{
  width: 48px;
  height: 5px;
  background-color: rgb(63, 63, 63);
  margin: 6px 0;
  transition: 0.4s;
}

.bar3{
  width: 48px;
  height: 5px;
  background-color: rgb(134, 134, 134);
  margin: 6px 0;
  transition: 0.4s;
}

.bar4{
  width: 48px;
  height: 5px;
  background-color: rgb(77, 77, 77);
  margin: 6px 0;
  transition: 0.4s;
}


.bar5{
  width: 20px;
  height: 7px;
  background-color: rgb(255, 255, 255);
  margin: 6px 0;
  transition: 0.7s;
  z-index: 99
}

.bar6 {
  width: 37.5px;
  height: 7px;
  background-color: rgb(255, 255, 255);
  margin: 6px 0;
  transition: 0.7s;
  z-index: 99
}

.bar7 {
  width: 37.5px;
  height: 5px;
  background-color: rgb(255, 255, 255);
  margin: 6px 0;
  transition: 0.7s;
  z-index: 99
}

/* Rotate first bar */
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(-75deg) translate(-22px, 18px) ;
}

/* Rotate second bar */
.change .bar2 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(75deg) translate(15px, 1.5px) ;
}

/* Rotate third bar */
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px) ;
transform: rotate(-75deg) translate(-3.5px,3px) ;
}

/* Rotate forth bar */
.change .bar4 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(75deg) translate(-2.9px, -14px) ;
}

/* Rotate fifth bar */
.change .bar6 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(90deg) translate(0px, -12.7px) ;
}

/* Rotate sixth bar */
.change .bar5 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(-90deg) translate(54px, 21.5px) ;
}


</style>

的JavaScript

<script>
function myFunction(x) {
x.classList.toggle("change");
}
</script>    

我还需要投入更多资料?这些酒吧作为我的标志,所以我不想让它们关闭,但与此同时,作为一个新手,我不知道如何在其中加入菜单。

谢谢!

0 个答案:

没有答案