js與css實(shí)現(xiàn)彈出層覆蓋整個頁面的方法
本文實(shí)例講述了js與css實(shí)現(xiàn)彈出層覆蓋整個頁面的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
彈出層透明背景加框的常用樣式和結(jié)構(gòu)如下:
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;
}
<div class="alertMessageBg"></div>
<div class="alertMessageDivBorder"></div>
<div class="alertMessageDiv"></div>
彈出層背景覆蓋整個網(wǎng)頁的方法
1.css方法
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方法
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的現(xiàn)在。
希望本文所述對大家基于JS的web程序設(shè)計(jì)有所幫助。
- js實(shí)現(xiàn)div彈出層的方法
- 使用js實(shí)現(xiàn)關(guān)閉js彈出層的窗口
- js 點(diǎn)擊頁面其他地方關(guān)閉彈出層(示例代碼)
- js寫一個彈出層并鎖屏效果實(shí)現(xiàn)代碼
- js+css 實(shí)現(xiàn)遮罩居中彈出層(隨瀏覽器窗口滾動條滾動)
- js彈出層之1:JQuery.Boxy (二)
- Js Jquery創(chuàng)建一個彈出層可加載一個頁面
- jquery.artwl.thickbox.js 一個非常簡單好用的jQuery彈出層插件
- Js制作簡單彈出層DIV在頁面居中 中間顯示遮罩的具體方法
- javascript實(shí)現(xiàn)彈出層效果
相關(guān)文章
JS實(shí)現(xiàn)運(yùn)動緩沖效果的封裝函數(shù)示例
這篇文章主要介紹了JS實(shí)現(xiàn)運(yùn)動緩沖效果的封裝函數(shù),涉及JavaScript時間函數(shù)與數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2018-02-02
JavaScript+CSS實(shí)現(xiàn)的可折疊二級菜單實(shí)例
這篇文章主要介紹了JavaScript+CSS實(shí)現(xiàn)的可折疊二級菜單,以完整實(shí)例形式分析了JavaScript基于頁面元素節(jié)點(diǎn)及樣式的動態(tài)操作實(shí)現(xiàn)折疊菜單的相關(guān)技巧,需要的朋友可以參考下2016-02-02
不使用jquery實(shí)現(xiàn)js打字效果示例分享
js打字效果示例js打字效果示例,data-period設(shè)置從打字返回刪字的時間,data-rotate可加減中英文詞語,不用jquery支持2014-01-01
關(guān)于導(dǎo)入excel時js轉(zhuǎn)換時間的正確方式
這篇文章主要給大家介紹了關(guān)于導(dǎo)入excel時js轉(zhuǎn)換時間的正確方式,以及js讀取excel中日期格式轉(zhuǎn)換問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09

