效果圖:
實現原理:
- 將彈窗內容寫在一個div裏面,設置display屬性爲none
- 按鈕點擊綁定事件,將上述div的display屬性改爲block
HTML代碼
<body>
<p>示例彈出頁:
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">
請點這裏
</a>
</p>
<div id="light" class="white_content">
<div id="font_login">Login in</div>
<form action="" method="post" id="form_submit">
賬號:<input type="text" name="" id="name" value="" /></br>
密碼:<input type="password" name="" id="password" value="" /></br>
<input type="button" value="確認" class="button_beautiful ceshi" />
<input type="button" value="取消" class="button_beautiful" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'" />
</form>
</div>
<div id="fade" class="black_overlay"></div>
</body>
CSS代碼:
.black_overlay {
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: #bbbbbb;
z-index: 1001;
opacity: .80;
}
.white_content {
display: none;
position: absolute;
top: 20%;
border: 1px solid #bbbbbb;
border-radius: 20px;
background-color: white;
z-index: 1002;
overflow: auto;
}
#light {
position: absolute;
left: 50%;
width: 300px;
height: 250px;
margin-left: -150px;
;
}
#form_submit {
text-align: center;
margin-left: 10px;
margin-top: 10px;
}
#font_login {
font-weight: 400;
font-size: 24px;
color: #BBBBBB;
text-align: center;
margin-top: 20px;
}
.button_beautiful {
width: 60px;
height: 34px;
border-width: 0px;
border-radius: 6px;
background: #4ECDC4;
cursor: pointer;
outline: none;
color: white;
font-size: 16px;
margin-top: 20px;
}
</style>
全部代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.black_overlay {
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: #bbbbbb;
z-index: 1001;
opacity: .80;
}
.white_content {
display: none;
position: absolute;
top: 20%;
border: 1px solid #bbbbbb;
border-radius: 20px;
background-color: white;
z-index: 1002;
overflow: auto;
}
#light {
position: absolute;
left: 50%;
width: 300px;
height: 250px;
margin-left: -150px;
;
}
#form_submit {
text-align: center;
margin-left: 10px;
margin-top: 10px;
}
#font_login {
font-weight: 400;
font-size: 24px;
color: #BBBBBB;
text-align: center;
margin-top: 20px;
}
.button_beautiful {
width: 60px;
height: 34px;
border-width: 0px;
border-radius: 6px;
background: #4ECDC4;
cursor: pointer;
outline: none;
color: white;
font-size: 16px;
margin-top: 20px;
}
</style>
</head>
<body>
<p>示例彈出頁:
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">
請點這裏
</a>
</p>
<div id="light" class="white_content">
<div id="font_login">Login in</div>
<form action="" method="post" id="form_submit">
賬號:<input type="text" name="" id="name" value="" /></br>
密碼:<input type="password" name="" id="password" value="" /></br>
<input type="button" value="確認" class="button_beautiful ceshi" />
<input type="button" value="取消" class="button_beautiful" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'" />
</form>
</div>
<div id="fade" class="black_overlay"></div>
</body>
</html>