バウンド(跳ねる)アニメーションで開くメニュー

HTML
<div class="menu-wrapper">
  <button class="bounce-button" id="menu-toggle">MENU</button>
  <nav class="bounce-menu" id="bounce-menu">
    <a href="#">TOP</a>
    <a href="#">ABOUT</a>
    <a href="#">WORKS</a>
    <a href="#">CONTACT</a>
  </nav>
</div>
CSS
.menu-wrapper {
  position: relative;
  text-align: center;
  margin-top: 40px;
}

.bounce-button {
  background: #008080;
  color: #fff;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: bold;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: background 0.3s;
}
.bounce-button:hover {
  background: #00aaaa;
}

.bounce-menu {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.bounce-menu a {
  background: #222;
  color: #fff;
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 1rem;
  opacity: 0;
  transform: translateY(20px);
  animation: none;
}

.bounce-menu.open a {
  pointer-events: auto;
  opacity: 1;
  animation: bounceIn 0.5s ease forwards;
}

.bounce-menu.open a:nth-child(1) { animation-delay: 0.05s; }
.bounce-menu.open a:nth-child(2) { animation-delay: 0.15s; }
.bounce-menu.open a:nth-child(3) { animation-delay: 0.25s; }
.bounce-menu.open a:nth-child(4) { animation-delay: 0.35s; }

@keyframes bounceIn {
  0%   { opacity: 0; transform: translateY(30px); }
  50%  { transform: translateY(-10px); }
  70%  { transform: translateY(5px); }
  100% { opacity: 1; transform: translateY(0); }
}
JavaScript
const toggleBtn = document.getElementById("menu-toggle");
const menu = document.getElementById("bounce-menu");

toggleBtn.addEventListener("click", () => {
  menu.classList.toggle("open");

  // アニメーションを毎回再生するためにリセット
  if (menu.classList.contains("open")) {
    toggleBtn.textContent = "CLOSE";
    const links = menu.querySelectorAll("a");
    links.forEach(link => {
      link.style.animation = "none";
      link.offsetHeight; // リフロー強制
      link.style.animation = "";
    });
  } else {
    toggleBtn.textContent = "MENU";
  }
});

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

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

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