簡體   English   中英

當我的漢堡菜單打開時如何禁用滾動?

[英]How can I disable scrolling when my hamburger menu is open?

我正在一個帶有漢堡菜單的網站上工作,單擊時會填滿整個頁面。 唯一的問題是導航打開時后面的頁面仍然滾動,我不知道如何在菜單打開時禁用滾動。 我試過改變溢出-y:隱藏,但它似乎不起作用。

這是菜單的 HTML:

 <div id="menu">
   
  <div class="logotext">
    <a href="index.html">ONWORD</a>
    </div>
   
   
  <input type="checkbox" id="myInput">
  <label for="myInput">
      <span class="bar top"></span>
      <span class="bar middle"></span>
      <span class="bar bottom"></span>
    </label>
  <aside>
    <div class="aside-section aside-left">
      <div class="aside-content">
        <p> Languages of the land</p>
      </div>
    </div>
    <div class="aside-section aside-right">
      <ul class="aside-list">
        <li><a href="startlearning.html" class="aside-anchor">Start Learning</a></li>
        <li><a href="languagemap.html" class="aside-anchor">Language Map</a></li>
        <li><a href="history.html" class="aside-anchor">History</a></li>
        <li><a href="stories.html" class="aside-anchor">Stories</a></li>
          <li><a href="contact.html" class="aside-anchor">Contact</a></li>
      </ul>
    </div>
  </aside>
 </div>

這是 CSS:

.logotext a {
    font-family: "Raleway", sans-serif;
    font-size: 20px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 2px;
    left: 1%;
    z-index: 99999;
    color: white; 
    position: absolute;
    padding-left: 19px;
    padding-right: 19px;
    padding-top: 22px;
    transition: 0.5s;
}

.logotext a:hover {
    -webkit-transform: scale(0.9);
    transition-delay: 200ms;
    transition-duration: 0.5s;
}


.aside-section {
  top: 0;
  bottom: 0;
  position: absolute;
  z-index: 99998;
  overflow: hidden;
  
}


.aside-left {
  display: none;
  width: 40%;
  left: 0;
   background-color: white;
  background-image: url(../img/menu1.jpeg);
    background-position: center;
    background-size: cover;
  -webkit-transform: translateY(-100%);
  -moz-transform: translateY(-100%);
  -ms-transform: translateY(-100%);
  -o-transform: translateY(-100%);
  transform: translateY(-100%);
  transition: transform 0.4s ease-in-out;
    z-index: 99998;
    position: fixed;
    overflow-y: hidden;
}

.aside-right {
  width: 100%;
  right: 0;
  background-color: #000000;
  -webkit-transform: translateX(100%);
  -moz-transform: translateX(100%);
  -ms-transform: translateX(100%);
  -o-transform: translateX(100%);
  transform: translateX(100%);
  transition: transform 0.4s ease-in-out;
    z-index: 99998;
    position: fixed;
    overflow-y: hidden;

 
}

.aside-list {
  list-style: none;
  padding: 0;
  margin: 0;
  margin-top: 160px;
  text-align: left;
  padding-left: 50px;
    z-index: 99998;
}

.aside-content {
  margin-top: 150px;
  padding: 0 40px;
  position: relative;
  color: #000000;
  text-align: center;
    z-index: 99998;

}

.aside-list li {
  margin-bottom: 20px;
    z-index: 99998;
    padding-bottom: 7px;
    
}

.aside-anchor::after {
  content: "";
  position: absolute;
  bottom: 0;
  background-color: #000000;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 3px;

}

.aside-anchor::before {
  border-radius: 3px;
  content: "";
  position: absolute;
  bottom: 0;
  background-color: #f5eded;
  left: 0;
  height: 1px;
  z-index: 1;
  width: 50%;
  -webkit-transition: transform 0.2s ease-in-out;
  -o-transition: transform 0.2s ease-in-out;
  transition: transform 0.2s ease-in-out;

}

.aside-anchor:hover:before {
  -webkit-transform: translateX(50%);
  -moz-transform: translateX(50%);
  -ms-transform: translateX(50%);
  -o-transform: translateX(50%);
  transform: translateX(50%);
    background-color: #dd8800;
 
}

.aside-anchor {
  padding-bottom: 5px;
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  position: relative;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 2px;
    font-weight: 600;

    
    
}

input[type="checkbox"] {
  display: none;
}

input[type="checkbox"]:checked ~ aside .aside-left {
  transform: translateY(0%);
}

input[type="checkbox"]:checked ~ aside .aside-right {
  transform: translateX(0%);
}

input[type="checkbox"]:checked ~ label .bar {
  background-color: #fff;
}

input[type="checkbox"]:checked ~ label .top {
  -webkit-transform: translateY(0px) rotateZ(45deg);
  -moz-transform: translateY(0px) rotateZ(45deg);
  -ms-transform: translateY(0px) rotateZ(45deg);
  -o-transform: translateY(0px) rotateZ(45deg);
  transform: translateY(0px) rotateZ(45deg);
}

input[type="checkbox"]:checked ~ label .bottom {
  -webkit-transform: translateY(-15px) rotateZ(-45deg);
  -moz-transform: translateY(-15px) rotateZ(-45deg);
  -ms-transform: translateY(-15px) rotateZ(-45deg);
  -o-transform: translateY(-15px) rotateZ(-45deg);
  transform: translateY(-15px) rotateZ(-45deg);
}

input[type="checkbox"]:checked ~ label .middle {
  width: 0;
  
}

.middle {
  margin: 0 auto;
}

label {
  top: 10px;
  display: inline-block;
  padding: 7px 10px;
  background-color: transparent;
  cursor: pointer;
  margin: 10px;
  position: absolute;
    z-index: 99999;
    text-align: right;
    right: 1%;
    transition: 0.5s;
    
}

label:hover {
     -webkit-transform: scale(0.9);
    transition-delay: 200ms;
    transition-duration: 0.5s;
}

.bar {
  display: block;
  background-color: #ffffff;
  width: 30px;
  height: 3px;
  border-radius: 5px;
  margin: 5px auto;
  transition: background-color 0.4s ease-in, transform 0.4s ease-in,
    width 0.4s ease-in;
    z-index: 99999;
    
    
}

.aside-section h1 {
  margin: 0;
  position: relative;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  text-align: center;
  font-size: 35px;
  font-family: 'BritishShorthair';
}



.aside-section p {
  font-size: 90px;
    text-align: center;
    line-height: 130px;
    font-family: 'BritishShorthair';
    margin-top: 0px;
    color: white;
}


@media (min-width: 992px) {
  h1 {
    font-size: 40px;
  }
  .aside-left {
    display: block;
  }

  .aside-right {
    width: 60%;
  }
}

當你說你設置溢出-y:隱藏。 你在身體上做過這個嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM