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;
top=500;
left = 500;
height=0;
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);
Obj.style.width = Document.body.clientWidth;
Obj.style.height = Document.body.clientHeight;
Obj.style.height = Window.screen.availHeight
Obj.style.display = "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);
Obj.style.display = "block";
Obj.style.position = "absolute";
Obj.style.zindex = "10";
Obj.style.overflow = "hidden";
Obj.style.width = width + "px";
Obj.style.height = height + "px";
var Position = getPosition ();
Leftadd = (position.width-width)/2;
Topadd = (position.height-height)/2;
Obj.style.top = (position.top + topadd) + "px";
Obj.style.left = (Position.left + leftadd) + "px";
Window.onscroll = function () {
var Position = getPosition ();
Obj.style.top = (position.top + topadd) + "px";
Obj.style.left = (Position.left + leftadd) + "px";
};
}
Implied
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 ')"/>
<!--mask-->
<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; "
</div>
<!--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 ')"/>
</div>
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