モーダルウィンドウ:ネイチャー|Modal Window: Nature
[Nature Inspired Modal]
A modal window inspired by natural elements with organic shapes and earthy colors. Features leaf-like patterns and natural gradients.
HTML
<div class="container">
<button class="modal-button">Nature Inspired Modal</button>
<div class="mask"></div>
<div class="modal">
<button class="close-btn">Close</button>
<div class="modal-content">
<p>[Nature Inspired Modal]</p>
<p>A modal window inspired by natural elements with organic shapes and earthy colors. Features leaf-like patterns and natural gradients.</p>
</div>
</div>
</div>
CSS
.container {
max-width: 800px;
margin: 0 auto;
text-align: center;
}
.modal-button {
padding: 15px 30px;
background: linear-gradient(135deg, #8BC34A 0%, #4CAF50 50%, #2E7D32 100%);
color: #fff;
border: none;
border-radius: 25px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(139, 195, 74, 0.3);
position: relative;
overflow: hidden;
}
.modal-button:hover {
background: linear-gradient(135deg, #4CAF50 0%, #2E7D32 50%, #8BC34A 100%);
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(139, 195, 74, 0.4);
}
.mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(139, 195, 74, 0.3);
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
backdrop-filter: blur(5px);
}
.mask.appear {
opacity: 1;
visibility: visible;
}
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0.8);
background: linear-gradient(135deg, #F1F8E9 0%, #DCEDC8 50%, #C8E6C9 100%);
padding: 40px;
border-radius: 16px;
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%;
box-shadow: 0 10px 30px rgba(139, 195, 74, 0.2);
border: 2px solid #8BC34A;
overflow: hidden;
}
.modal.appear {
opacity: 1;
visibility: visible;
transform: translate(-50%, -50%) scale(1);
}
.modal p {
color: #2E7D32;
font-weight: 600;
text-align: center;
margin-bottom: 24px;
position: relative;
z-index: 1;
}
.close-btn {
position: absolute;
top: 15px;
right: 15px;
width: 32px;
height: 32px;
background: rgba(139, 195, 74, 0.9);
color: #fff;
border: none;
border-radius: 50%;
font-size: 18px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
line-height: 1;
}
.close-btn:hover {
background: rgba(76, 175, 80, 0.9);
transform: scale(1.1);
box-shadow: 0 2px 8px rgba(139, 195, 74, 0.4);
}
/* レスポンシブ対応 */
@media (max-width: 768px) {
.modal {
width: 95%;
padding: 20px;
}
.modal p {
font-size: 14px;
}
.modal-button {
font-size: 14px;
padding: 10px 20px;
}
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
const modalBtn = document.querySelector('.modal-button');
const mask = document.querySelector('.mask');
const modal = document.querySelector('.modal');
const closeBtn = document.querySelector('.close-btn');
// モーダルを開く
modalBtn.addEventListener('click', () => {
mask.classList.add('appear');
modal.classList.add('appear');
});
// マスクをクリックして閉じる
mask.addEventListener('click', () => {
mask.classList.remove('appear');
modal.classList.remove('appear');
});
// 閉じるボタンをクリックして閉じる
closeBtn.addEventListener('click', () => {
mask.classList.remove('appear');
modal.classList.remove('appear');
});
// ESCキーで閉じる
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
mask.classList.remove('appear');
modal.classList.remove('appear');
}
});
});