一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

實現(xiàn)lightBox時的樣式與行為分離減少JS第1/2頁

[參與測試的瀏覽器:IE6 / IE7 / IE8 / FF3.5 / OP9.6 / SF4 / Chrome2 ]
[操作系統(tǒng):Windows]
本教程旨在實現(xiàn)lightBox時的樣式與行為分離,減少JS在各方面(全屏遮蔽、ie6中遮蔽select、雙向居中、高度自適應內(nèi)容等)的工作。
先上代碼:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Chomo" />
<link rel="start" title="Home" />
<title>全屏屏蔽、自動居中的lightBox</title>
<style type="text/css">
* { margin:0; padding:0; }
html,body { height:100%; overflow:hidden; font:12px/1.5 simsun;}
.myPage { line-height:3; overflow:auto; width:100%; height:100%;}
.lightBox,
.popupCover,
.popupIframe,
.popupComponent { position:absolute; left:0; top:0; width:100%; height:100%;}
.popupComponent { z-index:2; display:none;}
.popupIframe { display:none; _display:block; _filter:alpha(opacity=0);}
.popupCover { background:#000; opacity:0.7; *filter:alpha(opacity=70);}
.lightBox { text-align:center; overflow:auto;}
.lightBoxContent { display:inline-block; *display:inline; zoom:1; width:300px; padding:10px; background:#fff; border:5px solid #00b4ff; vertical-align:middle;}
.lightBoxMaxHeight { display:inline-block; vertical-align:middle; height:100%; *height:99.5%; width:1px; overflow:hidden; margin-left:-1px;}
.lightBoxWrapper { display:inline-block; *display:inline; zoom:1; text-align:left;}
.lightBoxClose { color:#f00;}
.lightBoxSubmit { margin-top:10px; padding-top:5px; border-top:1px solid #ccc;}
.lightBoxSubmit input { font-size:12px; padding:0 10px; overflow:visible; margin:0 5px;}
</style>
</head>
<body>
<div class="popupComponent" id="lightBox">
<iframe class="popupIframe"></iframe>
<div class="popupCover"></div>
<div class="lightBox">
<span class="lightBoxMaxHeight"></span>
<div class="lightBoxContent">
<div class="lightBoxWrapper">
當提示小于一行時文字居中[br]
</div>
<div class="lightBoxSubmit">
<input type="button" value="確定" onclick="hideLayer('lightBox')" />
<input type="button" value="取消" onclick="hideLayer('lightBox')" />
</div>
</div>
</div>
</div>
<div class="popupComponent" id="lightBox2">
<iframe class="popupIframe"></iframe>
<div class="popupCover"></div>
<div class="lightBox">
<div class="lightBoxContent">
<div class="lightBoxWrapper">
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度 當內(nèi)容已經(jīng)超過了一屏的高度[br]
</div>
<div class="lightBoxSubmit">
<input type="button" value="確定" onclick="hideLayer('lightBox2')" />
<input type="button" value="取消" onclick="hideLayer('lightBox2')" />
</div>
</div>
<span class="lightBoxMaxHeight"></span>
</div>
</div>
<div class="myPage">
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
<div style="text-align:center;"><input type="button" value="位于第一屏的按鈕" onclick="showLayer('lightBox')" /></div>
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
<select><option>一個用于測試IE6中是否能覆蓋住的select</option></select>[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
<select><option>又一個用于測試IE6中是否能覆蓋住的select</option></select>[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
<div style="text-align:center;"><input type="button" value="位于第二屏中的按鈕" onclick="showLayer('lightBox')" /><input type="button" value="當內(nèi)容已經(jīng)超過了一屏的高度" onclick="showLayer('lightBox2')" /></div>
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
</div>
<script>
function showLayer(id) {
document.getElementById(id).style.display = "block";
}
function hideLayer(id) {
document.getElementById(id).style.display = "none";
}
</script>
</body>
</html>

這個lightBox具備以下特性,大家可以通過修改代碼測一測 ^-^:

在頁面中任意一位置點開,均能完美遮屏(此時無法直接控制包括滾動條在內(nèi)的任意元素),IE6中無須隱藏即能遮蔽select元素(iframe遮蔽法的缺陷:遮蔽后,如果拖動滾動條,select仍會移至頂層)。
lightBox的高度自適應其內(nèi)容,并呈現(xiàn)完美的居中狀態(tài)。
內(nèi)容為單行時,居中顯示;內(nèi)容為多行時,居左顯示;內(nèi)容高度使lightBox超過屏高時呈現(xiàn)滾動條,并居頂顯示,讀者能完整閱讀。
如有興趣,構成這個lightBox的以下小技巧可供您參詳:

1. 全屏遮蔽的方法:

A. 隱藏html/body的滾動條。
B. 用一個div做遮罩,再用一個div做帶有滾動條的頁面,一個疊上面,一個疊下面。
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Chomo" />
<link rel="start" title="Home" />
<title>全屏遮蔽的方法</title>
<style type="text/css">
* {
margin:0; padding:0; /*--- 簡單的css reset,據(jù)說它的效率不高,請自行替換為高效的 ---*/
}
html,body {
height:100%; /*--- 有了這個高度,IE6下,body的子對象設置height:100%才有效 ---*/
overflow:hidden; /*--- 滅掉html或body產(chǎn)生的滾動條 ---*/
}
.page {
line-height:3;
overflow:auto; /*--- 滾動條就靠它了 ---*/
width:600px; height:400px; background:#f60; /*--- 暫時先做這么大,方便大家看清楚 ---*/
position:relative; left:50px; top:50px; /*--- 移動一點點,方便大家看清楚,把它去掉,遮罩的基本的效果就實現(xiàn)了 ---*/
}
.cover {
position:absolute;
width:600px; height:400px; background:#000;
opacity:0.7; *filter:alpha(opacity=70);
z-index:2;
}
</style>
</head>
<body>
<div class="cover"></div>
<div class="page">
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]假裝很豐富的內(nèi)容[br]
</div>
</body>
</html>

JavaScript技術實現(xiàn)lightBox時的樣式與行為分離減少JS第1/2頁,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 欧美另类杂交a | 午夜在线免费视频 | 国产精品精品国产 | 日韩欧美区 | 丁香六月综合激情 | 国产一区二区不卡免费观在线 | 性色aⅴ在线观看swag | 国产精品第九页 | 91成年人 | 欧美激情国产一区在线不卡 | 国产精品区免费视频 | 中国女人一级做受免费视频 | 黑人巨大videos极度另类 | 久久久久精彩视频 | 一二三四在线视频社区1 | 大象蕉国产情侣 | 久久中文字幕视频 | 很黄的网站在线观看 | 91新网址 | 久久97久久97精品免视看清纯 | 免费精品在线视频 | 性夜黄a爽爽免费视频国产 性夜影院爽黄e爽痛轻点www | 91最新视频在线观看 | 色婷五月综激情亚洲综合 | 看全色黄大色大片免费视频 | 国产精品久久99 | fefe66毛片免费看 | 免费亚洲网站 | 黄色免费在线视频 | 欧美性一交激情视频在线 | 色老板美国在线观看 | 激情综合网五月激情 | 成人午夜精品网站在线观看 | 国产精品久久久久久麻豆一区 | 亚洲伊人色图 | 真实国产乱子伦在线观看 | 精品精品国产自在久久高清 | 欧美一级特黄视频 | 浮力影院第一页小视频国产在线观看免费 | 国产网红福利 | 欧美videos极品另类 |