モーダル
JavaScript

Fade Scale Modal

フェード+スケールで開閉するモーダル。最も汎用的。

HTML
<button class="modal-trigger" id="open-btn">Open Modal</button>
<div class="modal-overlay" id="fade-modal">
  <div class="modal-box">
    <h3>Confirm</h3>
    <p>Are you sure you want to continue?</p>
    <button id="close-btn">Close</button>
  </div>
</div>
CSS
.modal-trigger {
  padding: 10px 24px;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 10;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 340px;
  transform: scale(.92);
  transition: transform .25s cubic-bezier(.16,1,.3,1);
}
.modal-overlay.open .modal-box {
  transform: scale(1);
}
.modal-box h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1a1a1a;
}
.modal-box p {
  font-size: 13px;
  color: #666;
  margin-bottom: 20px;
  line-height: 1.5;
}
.modal-box button {
  padding: 8px 20px;
  background: #f5f5f5;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: #1a1a1a;
}
JavaScript
const overlay = document.getElementById('fade-modal');
document.getElementById('open-btn').addEventListener('click', () => {
  overlay.classList.add('open');
});
overlay.addEventListener('click', (e) => {
  if (e.target === overlay) overlay.classList.remove('open');
});
document.getElementById('close-btn').addEventListener('click', () => {
  overlay.classList.remove('open');
});