Eject the simplest modular mask layer of JS code _javascript Tips

Source: Internet
Author: User
Suppose we have a container container as follows:
Copy Code code as follows:

<style type= "Text/css" >
#container {width:auto;height:auto; overflow:hidden;}
/* The Overflow:hidden property is primarily designed to automatically hide parts that exceed container, and this property is set to address IE8 and the following version of browser compatibility issues.
</style>
<div id= "Container" >
</div>


Now you have to pop a div layer on the Web page so that you can't manipulate container before you close the div layer that pops up.
So, first we need to define the div layer of the mask as follows:
Copy Code code as follows:

<div id= "Continer" >
<!-only so put the mask layer in the container.
<divid= "Shade" style= "width:1600px;height:900px;/* to the mask layer an initial size * * * >
<input name= "Close" id= "closed" value= "off" >
</div>
</div>

Next, is to use JS to make the mask layer always displayed on the screen does not operate the mask layer below the content, click the Close button to close the mask layer
Copy Code code as follows:

<script type= "Text/javascript" >
$ (function () {
// Gets the current browser's internal width and height
Varnwidth = window.innerwidth;
Varnheight = window.innerheight;
//sets the width and height of the mask layer
$ ("#shade"). Width (nwidth);
$ ("#shade"). Height (nheight);
//Set the Close button to center
$ ("#close"). CSS ("Margin-top", nheight/2-50+ "px");
//Set events that are triggered when the browser size changes
$ (window). Resize (function () {
//Get the current browser's internal width and height
Varnwidth = window.innerwidth;
Varnheight = window.innerheight;
//sets the width and height of the mask layer
$ ("#shade"). Width (nwidth);
$ ("#shade"). Height (nheight);
//Set the Close button to center
$ ("#putPwd"). CSS ("Margin-top", nheight/2-50+ "px");
});
//Set off button to eliminate mask layer
$ ("#close"). Click (function () {
$ ("#shade"). REMOVEATTR ("id");
$ ("#shade"). HTML ("");
});
//can also be written with pure JS
document.getElementById ("shade"). Style ...;
//Later said no good, if interested and will not write, you can contact me.
})
</script>

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.