フルスクリーンに展開するオーバーレイ型ハンバーガーメニュー

HTML
<div class="hamburger-wrapper">
  <button class="hamburger-static" id="hamburger-btn">
    <span></span>
    <span></span>
    <span></span>
  </button>
  <div class="menu-overlay" id="menu-overlay">
    <ul>
      <li><a href="#">TOP</a></li>
      <li><a href="#">ABOUT</a></li>
      <li><a href="#">WORKS</a></li>
      <li><a href="#">CONTACT</a></li>
    </ul>
  </div>
</div>
CSS
.hamburger-wrapper {
  position: relative;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 0;
}

.hamburger-static {
  width: 40px;
  height: 30px;
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  z-index: 200;
}

.hamburger-static span {
  display: block;
  position: absolute;
  width: 100%;
  height: 3px;
  background: #333;
  border-radius: 2px;
  left: 0;
  transition: all 0.3s ease;
}

.hamburger-static span:nth-child(1) {
  top: 0;
}
.hamburger-static span:nth-child(2) {
  top: 13px;
}
.hamburger-static span:nth-child(3) {
  top: 26px;
}

.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(17, 17, 17, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transform: scale(0);
  opacity: 0;
  transition: transform 0.5s ease, opacity 0.5s ease;
  z-index: 150;
}

.menu-overlay.open {
  transform: scale(1);
  opacity: 1;
}

.menu-overlay ul {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
}

.menu-overlay ul li {
  margin: 20px 0;
}

.menu-overlay ul li a {
  color: #fff;
  text-decoration: none;
  font-size: 2rem;
  font-weight: bold;
  transition: color 0.3s;
}

.menu-overlay ul li a:hover {
  color: #d60000;
}
JavaScript
const hamburger = document.getElementById("hamburger-btn");
const overlay = document.getElementById("menu-overlay");

hamburger.addEventListener("click", function () {
  overlay.classList.add("open");
});

overlay.addEventListener("click", function (e) {
  if (e.target === overlay) {
    overlay.classList.remove("open");
  }
});

🌟 有料会員限定素材を配布中!

ここでしか手に入らない特別デザイン素材を今すぐチェック!

有料会員ページを見る
目次