页面有Dialog弹框时,如何实现蒙尘沉浸式
蒙尘沉浸式效果通常是在全屏覆盖层(如模态对话框、弹窗等)出现时使用,给用户一种视觉上的沉浸感。以下是实现蒙尘沉浸式效果的一种方法:
position: fixed
和width
、height
属性来实现全屏覆盖。background-color
和opacity
属性来实现。overflow: hidden
属性来实现。linear-gradient
属性来实现。以下是一个简单的示例代码,展示如何实现蒙尘沉浸式效果:
<!DOCTYPE html>
<html>
<head>
<style>
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
}
.dialog {
position: relative;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.dialog::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9998;
border-radius: inherit;
}
</style>
</head>
<body>
<div class="overlay"></div>
<div class="dialog">
<h2>对话框标题</h2>
<p>这里是对话框的内容。</p>
<button>关闭</button>
</div>
<script>
// 当点击按钮时,隐藏对话框和覆盖层
document.querySelector("button").addEventListener("click", function() {
document.querySelector(".dialog").style.display = "none";
document.querySelector(".overlay").style.display = "none";
});
</script>
</body>
</html>
1 回答433 阅读✓ 已解决
1 回答464 阅读
431 阅读
426 阅读
384 阅读
369 阅读
412 阅读