有时候,我们在写项目的时候使用框架里的弹窗,并不能满足客户的需求,
又或者使用地框架有冲突的时候,这时我们只能使用原生的css,js去写一个弹窗。
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>原生的弹窗</title>
<style>
/* 遮挡层样式 */
.dialog-face {
position: fixed;
height: 100%;
width: 100%;
z-index: 10;
top: 0;
left: 0;
opacity: 0.5;
background: #000000;
}
/* 弹窗样式 */
.bg {
width: 500px;
height: 400px;
background-color: white;
border-radius: 5px;
box-shadow: 0px 3px 8px 0px rgba(0, 0, 0, 0.2);
/* 定位 居中 */
position: absolute;
left: 50%;
top: 50%;
margin-top: -200px;
margin-left: -250px;
/* 显示级别 */
z-index: 11;
}
/* 弹窗标题 */
.title {
color: #000000;
text-align: center;
height: 50px;
line-height: 50px;
cursor: move;
/*光标的样式*/
padding: 0;
font-size: 22px;
}
/* 弹窗上的关闭元素样式 */
.close {
position: absolute;
right: 6px;
top: -10px;
cursor: pointer;
text-decoration: none;
}
</style>
</head>
<body>
<button onclick="openPopup()">打开弹窗</button>
<!-- 弹窗 -->
<div id="popup" style="display: none;">
<!-- 弹窗遮蔽层 -->
<div class="dialog-face">
</div>
<!-- 弹窗内容层 -->
<div class="bg">
<div class="title">弹窗标题
<div class="close" onclick="closePopup()">×</div>
</div>
<div class="">
这是一个弹窗ヾ(≧∇≦*)ゝ
</div>
</div>
</div>
</body>
<script src="../js/jquery.min.js"></script>
<script>
// 打开弹窗
function openPopup() {
var popup = document.getElementById("popup")
popup.style.display = 'block';
}
// 关闭弹窗
function closePopup() {
var popup = document.getElementById("popup")
popup.style.display = 'none'
}
//点击遮蔽层关闭
$(".dialog-face").click(function () {
$("#popup").attr("style", "display:none")
})
</script>
</html>