【转载】JS+CSS实现带关闭按钮的DIV弹出窗口
2016-10-25 17:43
791 查看
<html>
<head>
<title>JS+CSS实现带关闭按钮的DIV弹出窗口</title>
<script>
function locking(){
document.all.ly.style.display="block";
document.all.ly.style.width=document.body.clientWidth;
document.all.ly.style.height=document.body.clientHeight;
document.all.Layer2.style.display='block';
}
function Lock_CheckForm(theForm){
document.all.ly.style.display='none';document.all.Layer2.style.display='none';
return false;
}
</script>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p align="center">
<input type="button" value="弹出DIV" onClick="locking()" />
</p>
<div id="ly" style="position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
z-index: 2; left: 0px; display: none;">
</div>
<!-- 浮层框架开始 -->
<div id="Layer2" align="center" style="position: absolute; z-index: 3; left: expression((document.body.offsetWidth-540)/2); top: expression((document.body.offsetHeight-170)/10);
background-color: #fff; display: none;" >
<table width="540" height="300" border="0" cellpadding="0" cellspacing="0" style="border: 0 solid #e7e3e7;
border-collapse: collapse ;" >
<tr>
<td style="background-color: #73A2d6; color: #fff; padding-left: 4px; padding-top: 2px;
font-weight: bold; font-size: 12px;" height="10" valign="middle">
<div align="right"><a href=JavaScript:; class="STYLE1" onClick="Lock_CheckForm(this);">[关闭]</a> </div></td>
</tr>
<tr>
<td height="130" align="center">
</td>
</tr>
</table>
</div>
<!-- 浮层框架结束-->
</body>
</html>
第二个:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#greyLayer{position:absolute;top:0;left:0;background-color:#fff;display:none;opacity:.5;filter:alpha(opacity=50)}
#privacyLayer{width:800px;height:500px;border:1px solid #656451;position:absolute;top:200px;left:300px;background-color:#fff;display:none;z-index:10000; text-align:center;}
#privacyLayer .title{line-height:30px;font-weight:bold;padding:0;margin:0;font-size:16px;text-align:center;background-color:#FFFFCF;border-bottom:1px solid #656451}
#privacyLayer .con{}
#privacyLayer .btn{line-height:20px;text-align:center;margin-top:20px;}
#privacyLayer .r{line-height:40px;color:#000;font-weight:bold;font-size:14px;}
#privacyLayer .c{line-height:40px;color:#000;font-size:13px;}
</style>
</head>
<body>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<script type="text/javascript">
function openPrivacyLayer(){
var greyLayer = document.getElementById('greyLayer');
with(greyLayer.style){
display = 'block';
height = document.body.scrollHeight+'px';
width = document.body.scrollWidth+'px';
}
var top1;
var left1;
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
{
diffY = document.documentElement.scrollTop;
left1 = document.documentElement.scrollLeft;
//alert(diffY);
}
else if (document.body){
diffY = document.body.scrollTop;
left1 = document.body.scrollLeft;
//alert(diffY);
}
else
{/*Netscape stuff*/}
var privacyLayer = document.getElementById('privacyLayer');
var xWidth = privacyLayer.currentStyle.width;
var xHeight = privacyLayer.currentStyle.height;
if (xWidth == 'null' || xWidth == '')
{
xWidth = window.getComputedStyle(privacyLayer,null).style.width;
xHeight = window.getComputedStyle(privacyLayer,null).style.width;
}
xWidth = parseInt(xWidth.replace("px",""),10);
xHeight = parseInt(xHeight.replace("px",""),10);
//alert(xHeight);
with(privacyLayer.style){
display = 'block';
left = left1+((window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body.offsetWidth)-xWidth)/2+'px';
top = diffY + ((window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.offsetHeight)-xHeight)/2+'px';
}
}
function closePrivacy(){
document.getElementById('greyLayer').style.display = 'none';
document.getElementById('privacyLayer').style.display = 'none';
}
</script>
<!--<div id="greyLayer"></div>本来是用这个,后来因为用它有的HTML标记比它先显示,所以不用了。-->
<iframe id="greyLayer" frameborder="0"></iframe>
<div id="privacyLayer">
<h1 class="title">
欢迎</h1>
<div class="r">
欢迎</div>
<div class="c">
欢迎
欢迎
欢迎
欢迎</div>
<div id="privacyContent" class="con">
<div cols="80" rows="25" wrap="virtual" style="width:90%;font-size:14.9px;height:320px;" readonly="readonly">
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
</div>
</div>
<div class="btn"><button onclick="closePrivacy()">阅读完毕,关闭窗口</button></div>
</div>
</div>
</body>
</html>
<head>
<title>JS+CSS实现带关闭按钮的DIV弹出窗口</title>
<script>
function locking(){
document.all.ly.style.display="block";
document.all.ly.style.width=document.body.clientWidth;
document.all.ly.style.height=document.body.clientHeight;
document.all.Layer2.style.display='block';
}
function Lock_CheckForm(theForm){
document.all.ly.style.display='none';document.all.Layer2.style.display='none';
return false;
}
</script>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p align="center">
<input type="button" value="弹出DIV" onClick="locking()" />
</p>
<div id="ly" style="position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
z-index: 2; left: 0px; display: none;">
</div>
<!-- 浮层框架开始 -->
<div id="Layer2" align="center" style="position: absolute; z-index: 3; left: expression((document.body.offsetWidth-540)/2); top: expression((document.body.offsetHeight-170)/10);
background-color: #fff; display: none;" >
<table width="540" height="300" border="0" cellpadding="0" cellspacing="0" style="border: 0 solid #e7e3e7;
border-collapse: collapse ;" >
<tr>
<td style="background-color: #73A2d6; color: #fff; padding-left: 4px; padding-top: 2px;
font-weight: bold; font-size: 12px;" height="10" valign="middle">
<div align="right"><a href=JavaScript:; class="STYLE1" onClick="Lock_CheckForm(this);">[关闭]</a> </div></td>
</tr>
<tr>
<td height="130" align="center">
</td>
</tr>
</table>
</div>
<!-- 浮层框架结束-->
</body>
</html>
第二个:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#greyLayer{position:absolute;top:0;left:0;background-color:#fff;display:none;opacity:.5;filter:alpha(opacity=50)}
#privacyLayer{width:800px;height:500px;border:1px solid #656451;position:absolute;top:200px;left:300px;background-color:#fff;display:none;z-index:10000; text-align:center;}
#privacyLayer .title{line-height:30px;font-weight:bold;padding:0;margin:0;font-size:16px;text-align:center;background-color:#FFFFCF;border-bottom:1px solid #656451}
#privacyLayer .con{}
#privacyLayer .btn{line-height:20px;text-align:center;margin-top:20px;}
#privacyLayer .r{line-height:40px;color:#000;font-weight:bold;font-size:14px;}
#privacyLayer .c{line-height:40px;color:#000;font-size:13px;}
</style>
</head>
<body>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<div><a href="javascript:void(0);" onclick="openPrivacyLayer()">显示</a></div>
<div style="width:100%; height:500px;background-color:#cc0000;"></div>
<script type="text/javascript">
function openPrivacyLayer(){
var greyLayer = document.getElementById('greyLayer');
with(greyLayer.style){
display = 'block';
height = document.body.scrollHeight+'px';
width = document.body.scrollWidth+'px';
}
var top1;
var left1;
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
{
diffY = document.documentElement.scrollTop;
left1 = document.documentElement.scrollLeft;
//alert(diffY);
}
else if (document.body){
diffY = document.body.scrollTop;
left1 = document.body.scrollLeft;
//alert(diffY);
}
else
{/*Netscape stuff*/}
var privacyLayer = document.getElementById('privacyLayer');
var xWidth = privacyLayer.currentStyle.width;
var xHeight = privacyLayer.currentStyle.height;
if (xWidth == 'null' || xWidth == '')
{
xWidth = window.getComputedStyle(privacyLayer,null).style.width;
xHeight = window.getComputedStyle(privacyLayer,null).style.width;
}
xWidth = parseInt(xWidth.replace("px",""),10);
xHeight = parseInt(xHeight.replace("px",""),10);
//alert(xHeight);
with(privacyLayer.style){
display = 'block';
left = left1+((window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body.offsetWidth)-xWidth)/2+'px';
top = diffY + ((window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.offsetHeight)-xHeight)/2+'px';
}
}
function closePrivacy(){
document.getElementById('greyLayer').style.display = 'none';
document.getElementById('privacyLayer').style.display = 'none';
}
</script>
<!--<div id="greyLayer"></div>本来是用这个,后来因为用它有的HTML标记比它先显示,所以不用了。-->
<iframe id="greyLayer" frameborder="0"></iframe>
<div id="privacyLayer">
<h1 class="title">
欢迎</h1>
<div class="r">
欢迎</div>
<div class="c">
欢迎
欢迎
欢迎
欢迎</div>
<div id="privacyContent" class="con">
<div cols="80" rows="25" wrap="virtual" style="width:90%;font-size:14.9px;height:320px;" readonly="readonly">
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
欢迎
</div>
</div>
<div class="btn"><button onclick="closePrivacy()">阅读完毕,关闭窗口</button></div>
</div>
</div>
</body>
</html>
相关文章推荐
- JS+CSS实现带关闭按钮DIV弹出窗口的方法
- JS+CSS实现带关闭按钮DIV弹出窗口的方法
- JS+CSS实现Div弹出窗口同时背景变暗的方法
- JS+CSS实现Div弹出窗口同时背景变暗的方法
- JS+CSS实现Div弹出窗口同时背景变暗的方法
- JS关闭窗口弹出新窗口,关闭新窗口时,刷新父窗口,JS代码实现刷新网页,js实现弹出窗口代码收集集萃
- CSS+JS实现点击文字弹出定时自动关闭的DIV层菜单
- CSS+JS实现点击文字弹出定时自动关闭DIV层菜单的方法
- abap 弹出窗口屏幕(screen)实现关闭右上角的关闭按钮事件
- jQuery弹出Div窗口居中显示、滚动跟随、关闭按钮以及几秒后自动消失
- 纯js+css实现 页面弹出div
- 用div实现弹出窗口,拖动,最大化,最小化,关闭
- HTML+CSS+JS实现左边栏滑动框带关闭按钮
- Div+Css+JS做弹出窗口
- CSS+JS实现点击文字弹出定时自动关闭DIV层菜单的方法
- Div+Css+JS做弹出窗口
- js 弹出div窗口 可移动 可关闭 (转)
- 弹出的锁定背景的DIV对话框,关闭按钮如何实现?
- js+CSS实现弹出居中背景半透明div层的方法
- abap 弹出窗口屏幕(screen)实现关闭右上角的关闭按钮事件