天天躁日日躁狠狠躁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頁,轉載需保留來源!

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

主站蜘蛛池模板: 日本色高清 | 柏木舞子在线 | 人成片在线观看亚洲无遮拦 | 久久理论片 | 国产人妻人伦精品9 | 国产精品婷婷久青青原 | 亚洲人成网77777色在线播放 | 久久日本精品国产精品 | 日本亚洲中文字幕无码区 | 明星三级电影 | 波多久久亚洲精品AV无码 | 明星三级电影 | 国产国产人免费观看在线视频 | 亚洲 日韩 自拍 视频一区 | 亚洲粉嫩美白在线 | 7m凹凸国产刺激在线视频 | 99久久综合国产精品免费 | 免费看国产精品麻豆 | 亚洲AV无码乱码国产麻豆P | 国产 欧美 亚洲 日韩视频 | 超碰v | 欧美男同gay粗大又长 | 91免费精品国自产拍在线可以看 | 亚洲精品国产熟女久久久 | 精品国产成人系列 | 深爱激情站 | 成人免费肉动漫无遮网站 | 67194成网页发布在线观看 | 欧美乱码卡一卡二卡四卡免费 | XXX国产麻豆HD真实乱 | 国产精品美女久久久久AV超清 | 黄桃AV无码免费一区二区三区 | 欧美日韩国产高清综合二区 | 中文在线中文资源 | 伦理片在线3348 | 欧美卡1卡2卡三卡2021精品 | 啊灬啊别停灬用力啊在线观看视频 | 99国产这里只有精品视频 | 亚洲 欧洲 国产 日产 综合 | 国产精品久久人妻无码网站一区无 | 艳妇臀荡乳欲伦岳TXT下载 |