Js+css Simple Implementation div Mask layer display hidden

Source: Internet
Author: User

Http://www.cnblogs.com/aspx-net/archive/2011/03/11/1981071.html

js+css Simple Implementation div Mask layer display hidden1 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2 < HTML xmlns = "http://www.w3.org/1999/xhtml" >
3 < head >
4 < title > DIV CSS Mask layer </title >
5 < SCRIPT language = "javascript" type = "Text/javascript" >
6 function Showdiv () {
7 document.getElementById ("BG"). Style.display = "block";
8 document.getElementById ("Show"). Style.display = "block";
9}
Ten function Hidediv () {
One document.getElementById ("BG"). Style.display = ' None ';
document.getElementById ("Show"). Style.display = ' None ';
13}
</script >
< style type = "Text/css" >
#bg {display:none; position:absolute; top:0%; left:0%; width:100%; height:100%; background-color:b lack; z-index:1001; -moz-opacity:0.7; Opacity:. 70; Filter:alpha (opacity=70); }
#show {display:none; position:absolute; top:25%; left:22%; width:53%; height:49%; padding:8px; bo rder:8px solid #E8E9F7; Background-color:white; z-index:1002; Overflow:auto; }
</Style >
< BODY >
< input ID = "Btnshow" type = "button" value = "show" onclick = "showdiv ();"/>
< div id = "bg" ></div >
< div id = "Show" > Test
< input ID = "Btnclose" type = "button" value = "close" onclick = "hidediv ();"/>
</div >
Num </body >
</HTML >

Copy the code above to the HTML page to see the effect.

The principle is relatively simple, that is, in the page to define a good need to display the div and mask layer of CSS, and then used in the OnClick event, through JS to control the style of two div: display= ' block ' or display= ' none '. You can realize the display and hiding of Div.

Note that the z-index of the two Div, displayed on the top of the div z-index must be larger than the z-index of the mask layer.

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.