JS+CSS realization of pop-up centered background semi-transparent div layer _javascript Tips

Source: Internet
Author: User

The example of this article describes the JS+CSS implementation of a pop-up centered background semi-transparent div layer method. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>js+css pop-up centered background semitransparent div layer </title>
<style type= "Text/css" >
body{margin:0px;}
#bg {width:100%;height:100%;top:0px;left:0px;position:absolute;filter:alpha (opacity=50); opacity:0.5 background: #000000; Display:none;}
#popbox {position:absolute;width:400px; height:400px; left:50%; top:50%; margin:-200px 0 0-200px; display:none; Background: #666666;}
</style>
<script type= "Text/javascript" >
function Pupopen () {
document.getElementById ("BG"). style.display= "Block";
document.getElementById ("PopBox"). style.display= "Block";
}
function Pupclose () {
document.getElementById ("BG"). style.display= "None";
document.getElementById ("PopBox"). style.display= "None";
}
</script>
<body>
</br>
CSS pop-up layer, or pop-up window, background translucent style pop-up box,</br> in the site login, user registration, bulletin tips are very suitable for use. </br>ie and Ff,op can be ~ pop-up windows, background translucent </br>
Principle: Two layers, a height and width are 100%, the other is you want to pop up the specific content of the window,</br> translucent in IE is used Filter:alpha (opacity=60), in non ie with opacity:0.60;
</br></br> <a href= "#" onclick= "Pupopen ()" > Click here to open the window </a>
<div id= "BG" ></div>
<div id= "PopBox" > two layers, one height and width are 100%, the other is the specific content of the window you want to pop up, translucent in IE is used Filter:alpha (opacity=60); opacity:0.60 in non ie ;
<br>
<br>
<br>
<a href= "#" onclick= "Pupclose ()" > Click Close Window </a>
</div>
</body>

I hope this article will help you with your JavaScript programming.

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.