CSS动画弹窗效果是一种使用CSS(层叠样式表)来创建动态视觉效果的技术。通过CSS的@keyframes规则和动画属性,可以实现弹窗的平滑显示和隐藏效果。
以下是一个简单的CSS动画弹窗效果的示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS动画弹窗效果</title>
<style>
.popup {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 300px;
padding: 20px;
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
z-index: 1000;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.overlay.active {
display: block;
animation: fadeIn 0.3s ease-in-out;
}
.popup.active {
display: block;
animation: slideIn 0.3s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideIn {
from { transform: translate(-50%, -50%) scale(0.5); }
to { transform: translate(-50%, -50%) scale(1); }
}
</style>
</head>
<body>
<button onclick="showPopup()">显示弹窗</button>
<div class="overlay" id="overlay"></div>
<div class="popup" id="popup">
<h2>提示信息</h2>
<p>这是一个弹窗示例。</p>
<button onclick="hidePopup()">关闭</button>
</div>
<script>
function showPopup() {
document.getElementById('overlay').classList.add('active');
document.getElementById('popup').classList.add('active');
}
function hidePopup() {
document.getElementById('overlay').classList.remove('active');
document.getElementById('popup').classList.remove('active');
}
</script>
</body>
</html>@keyframes规则定义正确。animation-name、animation-duration等)设置正确。will-change属性优化动画性能,例如:will-change属性优化动画性能,例如:通过以上方法,可以有效解决CSS动画弹窗效果中常见的问题。
没有搜到相关的沙龙