JS+CSS Implementation Mask Center pop-up layer

Source: Internet
Author: User

  This article describes the use of JS to implement the mask pop-up layer centered, and with the browser window scroll scroll, sample code as follows, interested friends can refer to the following

JS+CSS Implementation Mask Center pop-up layer (scrolling with browser window scroll bar)     code as follows: <!doctype html>  <head>  <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 files with About:blank, reduce requests */  Body{}{background: #ff F font:12px/1.5 Tahoma,geneva, 5b8b4f53, 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 **/  #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>  </head>  <body>  <div class= "wrap" >  <p>  I am the text I am the text I am the text I am the text I am the body I am the text I am the text   <br/>  I am the text I am the text I am the body I am the text I am the text I am the text I am the text   <br/>  I am the textI am the text I am the text I am the body 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 body of 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 ">  <h3> am I a pop-up layer with no center? </h3>  <p> Center Center Center Center Center </p>  <p> Center Centered Center Center </p>  <p> Center Centered Center Center < /p>  <p> 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 '; nbsp } } }) (document.getElementById (' Masklayer')   </script>  </body>    </html>     
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.