Implement your own custom frame and mask layer

Source: Internet
Author: User

Sometimes we need to achieve their own frame and popover mask layer effect, I would like to tell you have JavaScript to achieve the simplest of their own frame and frame mask layer effect, first write the mask layer of JavaScript, the code is as follows:

1. Cover Layer JS:

Get coordinates
function GetPosition () {
var top = Document.documentElement.scrollTop;
var left = Document.documentElement.scrollLeft;
var height = document.documentElement.clientHeight;
var width = document.documentElement.clientWidth;
left = 500;
width = 500;
Height = 300;
top = 300;
return {top:top, left:left, Height:height, width:width};
Mask input, display mask
function Showmask (ID) {
var obj = document.getElementById (ID); = Document.body.clientWidth; = Document.body.clientHeight; = Window.screen.availHeight = "block";
Hide Mask
function Hidemask (ID) {
document.getElementById (id). style.display = "None";
Show Bullet Box
function Showpop (ID) {
Showmask (' mask ');
var width = 300; The width of the popup box
var height = 250; The height of the popup box
var obj = document.getElementById (ID); = "block"; = "absolute"; = "10"; = "hidden"; = width + "px"; = height + "px";
var Position = getPosition ();
Leftadd = (position.width-width)/2;
Topadd = (position.height-height)/2; = ( + topadd) + "px"; = (Position.left + leftadd) + "px";
Window.onscroll = function () {
var Position = getPosition (); = ( + topadd) + "px"; = (Position.left + leftadd) + "px";

function Hidepop (ID) {
Hidemask (' mask ');
document.getElementById (id). style.display = "None";

The HTML for the mask layer and the bullet box is as follows:

<input type= "button" value= "Pop-up Box" onclick= "Showpop (' TCC ')"/>

        <div id= "Mask" style= "Filter:alpha (opacity=30 ); -moz-opacity:0.3; -khtml-opacity:0.3;
            opacity:0.3; Background-color: #000; width: 100%; height:100%; z-index:200;
            position:absolute; left:0; top:0; display: None Overflow:hidden; "
        <!--mask Ends--
        <!--pop-up layer----;
         <div id= "TCC" style= "Display:none;background-color: #00ffff; z-index:201;" >  
           <input type= "button" value= "Hide Popup Layer" onclick= "Hidepop (' TCC ')"/>

Using the above effect we can make a custom frame, the contents of the box can also be customized.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Implement your own custom frame and mask layer

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: 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.