SnippetUI

グラスモーフィズムモーダル

背景をぼかした美しいガラス風のモーダルダイアログ。

Tailwind CSSJavaScript

背景がすりガラスのように透けて見えるモダンなモーダルウィンドウです。

プレビュー (Preview)

Glassmorphism

This is a beautiful glassmorphism modal popup using Tailwind CSS backdrop-blur utilities.

ユースケースと特徴 (Use Cases & Features)

  • プロモーションや警告: ユーザーの注意を強く引きたい重要なメッセージや、アクションを要求するポップアップに最適です。
  • モダンなビジュアル: 背景をすりガラスのようにぼかす(グラスモーフィズム)ことで、背後のコンテキストを保ちつつ、前面のコンテンツを際立たせます。
  • 高級感の演出: 単なる単色の背景よりも、奥行きと透明感を感じさせ、洗練された印象を与えます。

デザインとUXのポイント (Design & UX)

  • 背景のぼかし: Tailwind CSSの backdrop-blur ユーティリティを使用して、背後の要素を美しくぼかしています。
  • 境界線と透明度: bg-white/20border-white/30 のように、半透明の背景色と境界線を組み合わせることで、リアルなガラスの質感を表現しています。
  • アニメーションの追加: モーダルが表示される際に、フェードインとわずかなスケールアップのアニメーションを加えることで、より自然な出現感を演出しています。

カスタマイズ方法 (Customization Guide)

  • すりガラスの強さ: backdrop-blur-mdbackdrop-blur-xl のクラスを変更することで、ぼかしの強度を調整できます。
  • カラーテーマの変更: 背景のオーバーレイ色(bg-black/20)や、モーダル自身のベースカラーを変更することで、ダークテーマやブランドカラーに合わせられます。

実装コード (Implementation)

<!-- Container with background to demonstrate glass effect -->
<div class="relative w-full h-screen bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center">
<button id="open-modal" class="px-6 py-2 bg-white/20 hover:bg-white/30 backdrop-blur-md text-white font-medium rounded-lg border border-white/30 transition-all">Open Modal</button>

<div id="glass-modal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-300">
  <!-- Overlay -->
  <div class="absolute inset-0 bg-black/20 backdrop-blur-sm"></div>
  
  <!-- Modal Box -->
  <div class="relative bg-white/20 dark:bg-black/30 backdrop-blur-xl border border-white/30 dark:border-white/10 rounded-2xl p-8 max-w-sm w-full shadow-2xl transform scale-95 transition-transform duration-300">
    <h3 class="text-xl font-bold text-white mb-2">Glassmorphism</h3>
    <p class="text-white/80 mb-6 text-sm">This is a beautiful glassmorphism modal popup using Tailwind CSS backdrop-blur utilities.</p>
    <button id="close-modal" class="w-full py-2 bg-white/20 hover:bg-white/30 text-white rounded-lg transition-colors font-medium border border-white/20">Close</button>
  </div>
</div>
</div>
<script>
const modal = document.getElementById('glass-modal');
const inner = modal.querySelector('.transform');

document.getElementById('open-modal').addEventListener('click', () => {
  modal.classList.remove('opacity-0', 'pointer-events-none');
  inner.classList.remove('scale-95');
  inner.classList.add('scale-100');
});

document.getElementById('close-modal').addEventListener('click', () => {
  modal.classList.add('opacity-0', 'pointer-events-none');
  inner.classList.add('scale-95');
  inner.classList.remove('scale-100');
});
</script>