[Participating browsers: IE6/IE7/IE8/FF3.5/OP9.6/SF4/Chrome2]
[Operating system: Windows]
This tutorial aims to achieve the separation of style and behavior in lightBox, reducing JS's work in various aspects (full screen masking, select masking in ie6, bidirectional center, highly adaptive content, etc.
First run the Code:
Copy codeThe Code is as follows:
<! 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" href = "http://www.14px.com" title = "Home"/>
<Title> lightBox with full screen shielding and Automatic Center </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">
Text center when the prompt is smaller than one line [br]
</Div>
<Div class = "lightBoxSubmit">
<Input type = "button" value = "OK" onclick = "hideLayer ('lightbox')"/>
<Input type = "button" value = "cancel" 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">
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br]
</Div>
<Div class = "lightBoxSubmit">
<Input type = "button" value = "OK" onclick = "hideLayer ('lightbox2 ')"/>
<Input type = "button" value = "cancel" onclick = "hideLayer ('lightbox2 ')"/>
</Div>
</Div>
<Span class = "lightBoxMaxHeight"> </span>
</Div>
</Div>
<Div class = "myPage">
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
<Div style = "text-align: center;"> <input type = "button" value = "button on the first screen" onclick = "showLayer ('lightbox ') "/> </div>
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
<Select> <option> A select statement used to test whether IE6 can overwrite </option> </select> [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
<Select> <option> another select statement used to test whether IE6 can overwrite </option> </select> [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
<Div style = "text-align: center;"> <input type = "button" value = "button in the second screen" onclick = "showLayer ('lightbox ') "/> <input type =" button "value =" when the content has exceeded the height of a screen "onclick =" showLayer ('lightbox2 ') "/> </div>
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
</Div>
<Script>
Function showLayer (id ){
Document. getElementById (id). style. display = "block ";
}
Function hideLayer (id ){
Document. getElementById (id). style. display = "none ";
}
</Script>
</Body>
</Html>
This lightBox has the following features. You can test it by modifying the code ^-^:
The screen can be completely masked by clicking any position on the page (at this time, it is impossible to directly control any elements including the scroll bar ), the select element can be masked without hiding in IE6 (iframe masking: After masking, if you drag the scroll bar, select will still be moved to the top layer ).
LightBox highly adapts its content and presents a perfect center state.
When the content is a single row, it is displayed in the center; when the content is multiple rows, it is displayed in the left; The content height makes the scroll bar appear when the lightBox exceeds the screen, and displays it in the top, so that readers can fully read it.
If you are interested, you can refer to the following tips for creating this lightBox:
1. Full Screen masking:
A. Hide the html/body scroll bar.
B. Use a div as a mask and a div as a page with a scroll bar.
Copy codeThe Code is as follows:
<! 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" href = "http://www.14px.com" title = "Home"/>
<Title> full screen masking </title>
<Style type = "text/css">
*{
Margin: 0; padding: 0;/* --- simple css reset. It is said that it is not efficient. Please replace it with efficient ---*/
}
Html, body {
Height: 100%;/* --- with this height, height: 100% is set for the sub-object of the body in IE6 ---*/
Overflow: hidden;/* --- destroy the scroll bar generated by html or body ---*/
}
. Page {
Line-height: 3;
Overflow: auto;/* --- the scroll bar depends on it ---*/
Width: 600px; height: 400px; background: # f60;/* --- make it so large that you can see it clearly ---*/
Position: relative; left: 50px; top: 50px;/* --- move a little bit, so that you can see it clearly and remove it. The basic effect of the mask is achieved ---*/
}
. 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">
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]
</Div>
</Body>
</Html>