js与css实现弹出层覆盖整个页面的方法
本文实例讲述了js与css实现弹出层覆盖整个页面的方法。分享给大家供大家参考。具体实现方法如下:
弹出层透明背景加框的常用样式和结构如下:
.alertMessageBg{
position:fixed;
_position:absolute;
width:100%;
height:100%;
left:0;
top:0;
background:#000;
opacity:0.5;
-moz-opacity:0.5;
filter:alpha(opacity=50);
z-index:97;
display:none;
}
.alertMessageDivBorder{
position:fixed;
_position:absolute;
width:750px;
height:370px;
left:50%;
top:50%;
margin:-185px 0 0 -375px;
background:#000;
filter:alpha(opacity=30);
-moz-opacity:0.3;
opacity:0.3;
z-index:98;
display:none;
}
.alertMessageDiv{
position:fixed;
_position:absolute;
width:730px;
height:350px;
left:50%;
top:50%;
margin:-175px 0 0 -365px;
background:#fff;
z-index:99;
display:none;
font-size:14px;
}
弹出层背景覆盖整个网页的方法
1.css方法
.alertMessageBg{
position:fixed;
_position:absolute;
width:100%;
height:100%;
left:0;
top:0;
background:#000;
opacity:0.5;
-moz-opacity:0.5;
filter:alpha(opacity=50);
z-index:97;
display:none;
}
2.js方法
.alertMessageBg{
position:absolute;
width:100%;
height:100%;
left:0;
top:0;
background:#000;
opacity:0.5;
-moz-opacity:0.5;
filter:alpha(opacity=50);
z-index:97;
display:none;
}
var bgWidth = document.body.clientWidth + 'px',
bgHeight = document.body.clientHeight + 'px',
alertBgNode = $('.alertMessageBg');
alertBgNode.css({'width':bgWidth,'height':bgHeight});
对比以上两种方法,显然css方法更省事,尤其在不用兼容ie6的现在。
希望本文所述对大家基于JS的web程序设计有所帮助。相关阅读:
jquery实现简单合拢与展开网页面板的方法
redhat 5.4下安装MYSQL全过程
win32下进程间通信(共享内存)实例分析
c#实现数据库事务示例分享
win10系统wifi信号很弱怎么办?win10系统wifi不稳定解决方法
PHP临时文件的安全性分析
深入剖析C++中的struct结构体字节对齐
IOS实现微信朋友圈相册评论界面的翻转过渡动画
SQL数据库存储过程示例解析
css3实现一款模仿iphone样式的注册表单
异步动态加载JS并运行(示例代码)
html+css给单独某一表格定义样式示例
JS实现文字向下滚动完整实例
Win10强制自动更新 KB3074681造成资源管理器崩溃