リップル波紋ボタン
クリック位置を起点に波紋が全面へ広がるマテリアルデザイン風の押下フィードバック。あらゆるボタンに汎用的に組み込めます。
ライブデモ
使用例(お題: カフェ MOON BREW)
この技法を「カフェ MOON BREW」というテーマのダミーサイトで実際に使った例です。
HTML
<!-- MOON BREW: メニュー詳細。注文ボタンにリップル波紋を主役で -->
<div class="mb">
<div class="mb__photo" role="img" aria-label="カフェラテの写真"></div>
<div class="mb__info">
<p class="mb__cat">SIGNATURE</p>
<h1 class="mb__name">琥珀カフェラテ</h1>
<p class="mb__desc">深煎りエスプレッソに、なめらかなスチームミルク。<br>キャラメルの余韻がふわりと続く一杯。</p>
<div class="mb__opts">
<span class="chip chip--on">Hot</span>
<span class="chip">Iced</span>
<span class="chip">+ショット</span>
</div>
<div class="mb__buy">
<span class="mb__price">¥620</span>
<button class="ripple" type="button">
<span class="ripple__txt">カートに追加</span>
</button>
</div>
<p class="mb__hint">ボタンを押すと波紋が広がります</p>
</div>
</div>
CSS
/* MOON BREW カフェ テーマ: クリーム/濃ブラウン/琥珀 */
* { box-sizing: border-box; }
body {
margin: 0;
font-family: "Hiragino Mincho ProN", "Segoe UI", system-ui, serif;
background: #f5ede1;
color: #2b1d12;
}
.mb {
height: 400px;
display: grid;
grid-template-columns: 44% 1fr;
}
/* 商品写真(CSSグラデでコーヒー風) */
.mb__photo {
background:
radial-gradient(circle at 50% 38%, #6f4a28 0%, #4a2f18 55%, #2b1d12 100%);
position: relative;
}
.mb__photo::after {
content: "";
position: absolute;
left: 50%;
top: 38%;
width: 120px;
height: 120px;
transform: translate(-50%, -50%);
border-radius: 50%;
background:
radial-gradient(circle at 40% 35%, #d9b388 0%, #c98a3b 45%, #8a5a2b 100%);
box-shadow: 0 18px 40px rgba(0,0,0,.4);
}
.mb__info {
padding: 30px 30px 24px;
display: flex;
flex-direction: column;
}
.mb__cat {
margin: 0;
font-size: 12px;
letter-spacing: .28em;
color: #c98a3b;
font-weight: 700;
font-family: "Segoe UI", system-ui, sans-serif;
}
.mb__name {
margin: 8px 0 0;
font-size: 28px;
font-weight: 700;
}
.mb__desc {
margin: 14px 0 0;
font-size: 13px;
line-height: 1.9;
color: #5a4633;
}
.mb__opts {
display: flex;
gap: 10px;
margin: 20px 0 0;
}
.chip {
font-size: 12px;
font-family: "Segoe UI", system-ui, sans-serif;
color: #6b513a;
border: 1px solid #d8c4ab;
background: #fbf6ee;
padding: 6px 14px;
border-radius: 999px;
}
.chip--on {
color: #fff;
background: #2b1d12;
border-color: #2b1d12;
}
.mb__buy {
margin-top: auto;
display: flex;
align-items: center;
gap: 16px;
}
.mb__price {
font-size: 24px;
font-weight: 700;
color: #2b1d12;
}
/* 主役: リップル波紋ボタン */
.ripple {
position: relative;
overflow: hidden;
margin-left: auto;
font-family: "Segoe UI", system-ui, sans-serif;
font-size: 14px;
font-weight: 700;
color: #fff;
background: linear-gradient(135deg, #c98a3b, #a86b28);
border: none;
padding: 14px 30px;
border-radius: 12px;
cursor: pointer;
box-shadow: 0 10px 24px rgba(201,138,59,.4);
}
.ripple__txt { position: relative; z-index: 1; }
.ripple__wave {
position: absolute;
border-radius: 50%;
transform: translate(-50%, -50%) scale(0);
background: rgba(255,255,255,.5);
pointer-events: none;
animation: ripple-out .6s ease-out forwards;
}
@keyframes ripple-out {
to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
.mb__hint {
margin: 12px 0 0;
font-size: 11px;
color: #9b876f;
font-family: "Segoe UI", system-ui, sans-serif;
}
@media (prefers-reduced-motion: reduce) {
.ripple__wave { animation-duration: .01s; }
}
JavaScript
// MOON BREW注文: クリック位置を起点に全面を覆う波紋を生成
(() => {
const btn = document.querySelector('.ripple');
if (!btn) return; // null安全
btn.addEventListener('pointerdown', (e) => {
const r = btn.getBoundingClientRect();
const x = e.clientX - r.left;
const y = e.clientY - r.top;
// クリック位置からボタン四隅までの最大距離を半径に(全面を覆う)
const far = Math.max(
Math.hypot(x, y),
Math.hypot(r.width - x, y),
Math.hypot(x, r.height - y),
Math.hypot(r.width - x, r.height - y)
);
const size = far * 2;
const wave = document.createElement('span');
wave.className = 'ripple__wave';
wave.style.width = wave.style.height = `${size}px`;
wave.style.left = `${x}px`;
wave.style.top = `${y}px`;
// アニメ終了後にDOMから除去(メモリリーク防止)
wave.addEventListener('animationend', () => wave.remove());
btn.appendChild(wave);
});
})();
コード
HTML
<!-- リップル波紋ボタン: クリック位置から波紋が広がる -->
<div class="stage">
<button class="ripple" type="button">
<span class="ripple__text">Tap me</span>
</button>
<p class="hint">どこを押しても、その位置から波紋が広がります</p>
</div>
CSS
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: "Segoe UI", system-ui, sans-serif;
background: linear-gradient(135deg, #f6f7fb 0%, #e7ecf6 100%);
}
.stage {
display: grid;
place-items: center;
gap: 20px;
}
/* ボタン本体: overflow:hidden で波紋を内側に閉じ込める */
.ripple {
position: relative;
overflow: hidden;
isolation: isolate;
padding: 18px 52px;
font-size: 17px;
font-weight: 600;
letter-spacing: .03em;
color: #fff;
border: none;
border-radius: 14px;
cursor: pointer;
background: linear-gradient(135deg, #4f6bff 0%, #6f3cff 100%);
box-shadow: 0 12px 28px rgba(79, 107, 255, .35);
transition: transform .12s ease, box-shadow .25s ease;
-webkit-tap-highlight-color: transparent;
}
.ripple:active {
transform: scale(.97);
}
.ripple__text {
position: relative;
z-index: 1;
}
/* JSで生成される波紋要素 */
.ripple__wave {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, .55);
transform: translate(-50%, -50%) scale(0);
pointer-events: none;
animation: ripple-expand .6s ease-out forwards;
}
@keyframes ripple-expand {
to {
transform: translate(-50%, -50%) scale(1);
opacity: 0;
}
}
.hint {
margin: 0;
font-size: 13px;
color: #6b7280;
}
@media (prefers-reduced-motion: reduce) {
.ripple__wave { animation-duration: .01ms; }
}
JavaScript
// リップル波紋: クリック位置を起点に、ボタンを覆うサイズの円を生成
(() => {
const btn = document.querySelector('.ripple');
if (!btn) return; // null安全
btn.addEventListener('pointerdown', (e) => {
const r = btn.getBoundingClientRect();
// クリック位置からボタン四隅までの最大距離を半径に(全面を覆う)
const x = e.clientX - r.left;
const y = e.clientY - r.top;
const far = Math.max(
Math.hypot(x, y),
Math.hypot(r.width - x, y),
Math.hypot(x, r.height - y),
Math.hypot(r.width - x, r.height - y)
);
const size = far * 2;
const wave = document.createElement('span');
wave.className = 'ripple__wave';
wave.style.width = wave.style.height = `${size}px`;
wave.style.left = `${x}px`;
wave.style.top = `${y}px`;
// アニメ終了後にDOMから除去(メモリリーク防止)
wave.addEventListener('animationend', () => wave.remove());
btn.appendChild(wave);
});
})();
🤖 AIエージェント用プロンプト
このままコピーしてAIに貼り付け「追加する場所」だけ書き換えればOK
あなたは熟練のフロントエンドエンジニアです。私のWebサイトに「リップル波紋ボタン」の効果を追加してください。
# 追加してほしい効果
リップル波紋ボタン(マイクロインタラクション)
クリック位置を起点に波紋が全面へ広がるマテリアルデザイン風の押下フィードバック。あらゆるボタンに汎用的に組み込めます。
# 追加する場所
👉【ここに対象箇所を記入:例「トップのヒーローセクション」「お問い合わせボタン」「記事カードの一覧」など】
# 参考実装(この見た目・挙動を再現してください)
【HTML】
<!-- リップル波紋ボタン: クリック位置から波紋が広がる -->
<div class="stage">
<button class="ripple" type="button">
<span class="ripple__text">Tap me</span>
</button>
<p class="hint">どこを押しても、その位置から波紋が広がります</p>
</div>
【CSS】
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: "Segoe UI", system-ui, sans-serif;
background: linear-gradient(135deg, #f6f7fb 0%, #e7ecf6 100%);
}
.stage {
display: grid;
place-items: center;
gap: 20px;
}
/* ボタン本体: overflow:hidden で波紋を内側に閉じ込める */
.ripple {
position: relative;
overflow: hidden;
isolation: isolate;
padding: 18px 52px;
font-size: 17px;
font-weight: 600;
letter-spacing: .03em;
color: #fff;
border: none;
border-radius: 14px;
cursor: pointer;
background: linear-gradient(135deg, #4f6bff 0%, #6f3cff 100%);
box-shadow: 0 12px 28px rgba(79, 107, 255, .35);
transition: transform .12s ease, box-shadow .25s ease;
-webkit-tap-highlight-color: transparent;
}
.ripple:active {
transform: scale(.97);
}
.ripple__text {
position: relative;
z-index: 1;
}
/* JSで生成される波紋要素 */
.ripple__wave {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, .55);
transform: translate(-50%, -50%) scale(0);
pointer-events: none;
animation: ripple-expand .6s ease-out forwards;
}
@keyframes ripple-expand {
to {
transform: translate(-50%, -50%) scale(1);
opacity: 0;
}
}
.hint {
margin: 0;
font-size: 13px;
color: #6b7280;
}
@media (prefers-reduced-motion: reduce) {
.ripple__wave { animation-duration: .01ms; }
}
【JavaScript】
// リップル波紋: クリック位置を起点に、ボタンを覆うサイズの円を生成
(() => {
const btn = document.querySelector('.ripple');
if (!btn) return; // null安全
btn.addEventListener('pointerdown', (e) => {
const r = btn.getBoundingClientRect();
// クリック位置からボタン四隅までの最大距離を半径に(全面を覆う)
const x = e.clientX - r.left;
const y = e.clientY - r.top;
const far = Math.max(
Math.hypot(x, y),
Math.hypot(r.width - x, y),
Math.hypot(x, r.height - y),
Math.hypot(r.width - x, r.height - y)
);
const size = far * 2;
const wave = document.createElement('span');
wave.className = 'ripple__wave';
wave.style.width = wave.style.height = `${size}px`;
wave.style.left = `${x}px`;
wave.style.top = `${y}px`;
// アニメ終了後にDOMから除去(メモリリーク防止)
wave.addEventListener('animationend', () => wave.remove());
btn.appendChild(wave);
});
})();
# 外部ライブラリ
なし(追加ライブラリ不要)
# 守ってほしいこと
- 既存のHTML構造・レイアウト・デザインを壊さないこと。必要に応じてクラス名・色・サイズを私のサイトに合わせて調整してよい。
- クラス名やidが既存と衝突しないよう、必要なら接頭辞で名前空間を分けること。
- レスポンシブ対応と prefers-reduced-motion への配慮を入れること。
- 私のサイトのフレームワーク(React / Vue / 素のHTML など)に合わせて実装すること。不明な場合は素のHTML/CSS/JSで提示し、組み込み手順も説明すること。
- 変更後の確認手順も簡潔に教えてください。