天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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

[參與測試的瀏覽器:IE6 / IE7 / IE8 / FF3.5 / OP9.6 / SF4 / Chrome2 ]
[操作系統:Windows]
本教程旨在實現lightBox時的樣式與行為分離,減少JS在各方面(全屏遮蔽、ie6中遮蔽select、雙向居中、高度自適應內容等)的工作。
先上代碼:
復制代碼 代碼如下:
<!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">
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[br]
當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度 當內容已經超過了一屏的高度[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">
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
<div style="text-align:center;"><input type="button" value="位于第一屏的按鈕" onclick="showLayer('lightBox')" /></div>
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
<select><option>一個用于測試IE6中是否能覆蓋住的select</option></select>[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
<select><option>又一個用于測試IE6中是否能覆蓋住的select</option></select>[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
<div style="text-align:center;"><input type="button" value="位于第二屏中的按鈕" onclick="showLayer('lightBox')" /><input type="button" value="當內容已經超過了一屏的高度" onclick="showLayer('lightBox2')" /></div>
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[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具備以下特性,大家可以通過修改代碼測一測 ^-^:

在頁面中任意一位置點開,均能完美遮屏(此時無法直接控制包括滾動條在內的任意元素),IE6中無須隱藏即能遮蔽select元素(iframe遮蔽法的缺陷:遮蔽后,如果拖動滾動條,select仍會移至頂層)。
lightBox的高度自適應其內容,并呈現完美的居中狀態。
內容為單行時,居中顯示;內容為多行時,居左顯示;內容高度使lightBox超過屏高時呈現滾動條,并居頂顯示,讀者能完整閱讀。
如有興趣,構成這個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,據說它的效率不高,請自行替換為高效的 ---*/
}
html,body {
height:100%; /*--- 有了這個高度,IE6下,body的子對象設置height:100%才有效 ---*/
overflow:hidden; /*--- 滅掉html或body產生的滾動條 ---*/
}
.page {
line-height:3;
overflow:auto; /*--- 滾動條就靠它了 ---*/
width:600px; height:400px; background:#f60; /*--- 暫時先做這么大,方便大家看清楚 ---*/
position:relative; left:50px; top:50px; /*--- 移動一點點,方便大家看清楚,把它去掉,遮罩的基本的效果就實現了 ---*/
}
.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">
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]假裝很豐富的內容[br]
</div>
</body>
</html>

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

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

主站蜘蛛池模板: 国产97碰免费视频 | 最近的2019中文字幕HD | 国产一区二区波多野结衣 | 无码区国产区在线播放 | 强奷乱码欧妇女中文字幕熟女 | 欧美成人无码A区在线观看免费 | 香蕉视频国产精品 | 嫩草亚洲国产精品 | 久草在线福利资站免费视频 | brazzers情欲狂欢| 极品少妇小泬50PTHEPON | 亚洲女人毛片 | 超级碰碰青草久热国产 | 特级做A爰片毛片免费69 | 99精产国品一二产区在线 | 欧美日韩亚洲中字二区 | 国产精品一区二区亚瑟不卡 | 午夜国产一区在线观看 | 久久超碰色中文字幕 | 国产成人在线小视频 | 国产精品美女久久久网站动漫 | 秋霞av伦理片在线观看 | 被窝国产理论一二三影院 | 超碰免费视频公开观看 | 亚洲色婷婷久久精品AV蜜桃久久 | 国外成人电台 | 快播金瓶梅 | 儿子操妈妈 | 无人区乱码区1卡2卡三卡在线 | 国产午夜精品一区二区三区 | xxx69欧美| 老司机午夜影院试看区 | 欧美特级特黄AAAAA片 | 国产中文在线 | 激情综合色| 偷窥 亚洲 色 国产 日韩 | 日本妈妈在线观看中文字幕 | 亚洲欧美日韩精品自拍 | 国产久久re6免费热在线 | 成人网络电视破解版 | 久久91精品国产91久 |