This example describes the JS+CSS implementation of a full-screen gray-black transparent matte effect. Share to everyone for your reference. The specific analysis is as follows:
In many sites have such an effect, when a certain operation, will pop up a gray-black translucent mask, which can operate the specified content, such as a landing box can be ejected, such as the content, the following describes how to achieve this effect, code examples are as follows:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>css How to implement a full-screen gray-black transparent matte effect-cloud-Habitat Community </title>
<style type= "Text/css" >
*
{
margin:0px;
padding:0px;
}
. Zhezhao
{
width:100%;
height:100%;
Background-color: #000;
Filter:alpha (OPACITY=50);
-moz-opacity:0.5;
opacity:0.5;
Position:absolute;
left:0px;
top:0px;
Display:none;
z-index:1000;
}
. Login
{
width:280px;
height:180px;
Position:absolute;
top:200px;
left:50%;
Background-color: #000;
margin-left:-140px;
Display:none;
z-index:1500;
}
. Content
{
margin-top:50px;
color:red;
line-height:200px;
height:200px;
Text-align:center;
}
</style>
<script type= "Text/javascript" >
Window.onload=function ()
{
var Zhezhao=document.getelementbyid ("Zhezhao");
var Login=document.getelementbyid ("Login");
var Bt=document.getelementbyid ("BT");
var Btclose=document.getelementbyid ("Btclose");
Bt.onclick=function ()
{
zhezhao.style.display= "Block";
login.style.display= "Block";
}
Btclose.onclick=function ()
{
Zhezhao.style.display= "None";
Login.style.display= "None";
}
}
</script>
<body>
<div class= "Zhezhao" id= "Zhezhao" ></div>
<div class= "Login" id= "login" ><button id= "Btclose" > click Close </button></div>
<div class= "Content" > cloud-dwelling community welcome, <button id= "BT" > click Pop-up Mask </button></div>
</body>
The above implementation of the basic mask function, when clicked Pop-up Mask, will pop an object, when the click Off, mask effect disappears. Here's how to implement the secondary effect:
Implementation principle:
Create a full screen div, use absolute positioning, so that it can be detached from the document flow, no impact on other elements, and set it to semitransparent state, of course, this transparency can be arbitrarily tuned, while creating a login element, it also uses absolute positioning, and its Z-index property value is greater than the face screen Div, this time it will not be Mansi div obscured. The Display property value of these two div is none in the default state. When you click the corresponding button, you can change their display property values.
suggestion: as far as possible handwriting code, can effectively improve the learning efficiency and depth.
I hope this article will help you with your Web programming.