Modal / 19 ホログラフィック|Holographic
デザイン見本
複数色を用いたアニメーションするグラデーション(`linear-gradient` + `@keyframes`)で、CDの裏面のような虹色のホログラム表現を実装しています。ホバー時にアニメーションの速度が変化します。
実装コード
HTML
<!-- モーダルを開くボタン -->
<button class="modal-button">Holographic Modal</button>
<!-- モーダルの背景マスク -->
<div class="mask"></div>
<!-- モーダル本体 -->
<div class="modal">
<div class="modal-content">
<p>【Holographic Modal】</p>
<p>虹色に輝くホログラフィックなモーダルウィンドウです。</p>
<div class="close-btn-container">
<button class="close-btn">Close</button>
</div>
</div>
</div>
CSS
/* 開くボタンのスタイル */
.modal-button {
padding: 15px 30px;
background: linear-gradient(45deg, #ff0080, #ff8c00, #40e0d0, #ee82ee, #ff0080);
background-size: 400% 400%;
color: #fff;
border: none;
border-radius: 25px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
animation: holographicShift 3s ease infinite;
box-shadow: 0 4px 15px rgba(255, 0, 128, 0.3);
text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
@keyframes holographicShift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.modal-button:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(255, 0, 128, 0.5);
animation: holographicShift 1.5s ease infinite;
}
/* 背景マスクスタイル */
.mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 0, 128, 0.3);
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.mask.appear {
opacity: 1;
visibility: visible;
}
/* モーダル本体のスタイル */
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0.8);
background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
padding: 40px;
border-radius: 20px;
z-index: 1001;
opacity: 0;
visibility: hidden;
transition: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
max-width: 500px;
width: 90%;
backdrop-filter: blur(20px);
border: 2px solid transparent;
background-clip: padding-box;
overflow: hidden;
}
.modal.appear {
opacity: 1;
visibility: visible;
transform: translate(-50%, -50%) scale(1);
}
/* モーダル枠のホログラム光沢 */
.modal::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(45deg, #ff0080, #ff8c00, #40e0d0, #ee82ee, #ff0080);
background-size: 400% 400%;
animation: holographicShift 4s ease infinite;
border-radius: 20px;
z-index: -1;
margin: -2px;
}
.modal::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
border-radius: 20px;
z-index: -1;
margin: 2px;
}
.modal p {
color: #fff;
font-weight: 600;
text-align: center;
margin-bottom: 24px;
position: relative;
z-index: 2;
text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}
/* 閉じるボタンスタイル */
.close-btn {
padding: 12px 24px;
background: linear-gradient(45deg, #ff0080, #ff8c00);
color: #fff;
border: none;
border-radius: 25px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: block;
margin: 0 auto;
position: relative;
z-index: 2;
box-shadow: 0 4px 15px rgba(255, 0, 128, 0.3);
}
.close-btn:hover {
background: linear-gradient(45deg, #ff8c00, #40e0d0);
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(255, 0, 128, 0.4);
}
JS
(function () {
var btn = document.querySelector('.modal-button');
var mask = document.querySelector('.mask');
var modal = document.querySelector('.modal');
var closeBtns = document.querySelectorAll('.close-btn');
if (!btn || !mask || !modal) return;
function openModal() {
mask.classList.add('appear');
modal.classList.add('appear');
}
function closeModal() {
mask.classList.remove('appear');
modal.classList.remove('appear');
}
// ホバー時のアニメーション加速エフェクト
modal.addEventListener('mouseenter', function () {
this.style.animation = 'holographicShift 2s ease infinite';
});
modal.addEventListener('mouseleave', function () {
this.style.animation = 'none'; // アニメーションは疑似要素に定義されているので本来は不要かもですが元のJSを踏襲
});
btn.addEventListener('click', openModal);
mask.addEventListener('click', closeModal);
closeBtns.forEach(function(b) { b.addEventListener('click', closeModal); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && modal.classList.contains('appear')) {
closeModal();
}
});
})();