1. Make the layer always appear in the middle of the screen:
Style code:
HTML code
- . model{
- Position:absolute; z-index:1003;
- width:320px; height:320px; Text-align:center;
- Background-color: #0066FF; Display:none;
- }
jquery Code:
JS Code
- Make the specified div always appear in the middle of the screen
- function Letdivcenter (divname) {
- var top = ($ (window). Height ()-$ (divname). Height ())/2;
- var left = ($ (window). Width ()-$ (divname). Width ())/2;
- var scrolltop = $ (document). ScrollTop ();
- var scrollleft = $ (document). ScrollLeft ();
- $ (divname). css ({position: ' absolute ', ' top ': Top + scrolltop, Left:left + scrollleft}). Show ();
- }
HTML code:
HTML code
- <a href="javascript:;" onclick="letdivcenter (' #model ')"> Point I let div always show in the middle of the screen </a><br / >
- <div>
- <div id="model" class="model">
- This is the content (but not the vertical center display) I hope you master, can add. My little brother thanked me here.
- </div>
- </div>
Run it and look at the effect.
Next, summarize them and combine them into one. That is, when the div layer pops up, but also to pop up the mask layer, good, no nonsense to say, look at the code:
1. CSS style:
HTML code
- <style type="Text/css">
- . Mask {
- Position:absolute; top:0px; Filter:alpha (opacity=); Background-color: #777;
- z-index:1002; left:0px;
- opacity:0.5; -moz-opacity:0.5;
- }
- . model{
- Position:absolute; z-index:1003;
- width:320px; height:320px; Text-align:center;
- Background-color: #0066FF; Display:none;
- }
- </style>
2. jquery Code:
HTML code
- <script type="Text/javascript">
- Compatible with Firefox, IE8
- function Showmask () {
- $ ("#mask"). CSS ("height", $ (document). Height ());
- $ ("#mask"). CSS ("width", $ (document). width ());
- $ ("#mask"). Show ();
- }
- Make the specified div always appear in the middle of the screen
- function Letdivcenter (divname) {
- var top = ($ (window). Height ()-$ (divname). Height ())/2;
- var left = ($ (window). Width ()-$ (divname). Width ())/2;
- var scrolltop = $ (document). ScrollTop ();
- var scrollleft = $ (document). ScrollLeft ();
- $ (divname). css ({position: ' absolute ', ' top ': Top + scrolltop, Left:left + scrollleft}). Show ();
- }
- function ShowAll (divname) {
- Showmask ();
- Letdivcenter (Divname);
- }
- </Script>
3.HTML Code:
HTML code
- <div id="Mask" class="Mask"></div>
- <a href= "javascript:;" onclick= "Showmask ()" > Dot I show mask layer </a>< br />
- <a href= "javascript:;" onclick= "Letdivcenter (' #model ')" > Dot I let div always show in the middle of the screen </a>< br />
- <a href="javascript:;" onclick="showall (' #model ')"> Point I show All </a><br />
- <div>
- <div id="model" class="model">
- This is the content (but not the vertical center display) I hope you master, can add. My little brother thanked me here.
- </div>
- </div>
JQuery pop-up layer, always displayed in the middle of the screen