JS+CSS Implement the Mask Center pop-up layer (scrolling with the browser window scroll bar) _javascript tips

Source: Internet
Author: User
JS+CSS Implementation Mask Center pop-up layer (scroll with browser window scroll bar)
Copy Code code as follows:

<!doctype html>
<meta charset= "Utf-8"/>
<title></title>
<style type= "Text/css" >
*{}{margin:0;padding:0;}
Html{}{_background:url (About:blank);}/**//* prevent flashing in IE6, replace empty file with About:blank, reduce request * *
Body{}{background: #fff; font:12px/1.5 Tahoma,geneva, \\5b8b\\4f53, Sans-serif; height:100%;}
. wrap{}{height:980px; padding-top:20px;text-align:center;}
p{}{font-size:14px;text-align:center;line-height:24px;}
/**//** Mask Layer **/
#masklayer {} {
Background: #000;
Display:none;
Filter:alpha (opacity = 50);
opacity:0.5;
top:0;
left:0;
height:100%;
width:100%;
z-index:999;
position:fixed;
_position:absolute;
_left:expression (Documentelement.scrollleft + documentelement.clientwidth-this.offsetwidth);
_top:expression (Documentelement.scrolltop + documentelement.clientheight-this.offsetheight);
}
/**//** Pop-up layer **/
#popup {} {
Display:none;
width:300px;
z-index:1000;
left:50%;
top:50%;
Position:fixed!important;
margin-left:-150px!important;
_position:absolute;
_top:expression (eval (document.compatmode && document.compatmode== ' Css1compat ')?
Documentelement.scrolltop + (Document.documentelement.clientheight-this.offsetheight)/2:/**//*IE6*/
Document.body.scrollTop + (Document.body.clientheight-this.clientheight)/2); /**//*IE5 ie5.5*/
}
. Content{}{background: #f3f3f3; border:1px solid #999;}
. Content h3{}{background: #a0a0a0; color: #fff; font-size:14px;height:32px;line-height:32px; padding-left:5px;}
#clickbtn {}{margin-top:20px;}
</style>
<body>
<div class= "Wrap" >
<p>
I am the text I am the text I am the text I am the text I am the text I am the text
<br/>
I am the text I am the text I am the text I am the text I am the text I am the text
<br/>
I am the text I am the text I am the text I am the text I am the text I am the text
<br/>
I am the text I am the text I am the text I am the text I am the text I am the text
<br/>
I am the text I am the text I am the text I am the text I am the text I am the text
</p>
<input type= "button" id= "clickbtn" value= "Clike Me"/>
</div>
<div id= "Masklayer" ></div>
<div id= "Popup" >
<div class= "Content" >
<p> Center Centered Center center </p>
<p> Center Center Center Center </p>
<p> Center Center Center </p>
<p> Center Center Center </p>
</div>
</div>
<script type= "Text/javascript" >
(function (Masklayer) {
var clickbtn = document.getElementById (' clickbtn ');
Clickbtn.onclick = function () {
var popup = document.getElementById (' popup ');
masklayer.style.display= ' block ';
Popup.style.display = ' block ';
var h = popup.clientheight;
With (Popup.style) {
MarginTop =-h/2+ ' px ';
}
}
}) (document.getElementById (' Masklayer '))
</script>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.