Implement custom bullet box and mask layers and custom mask Layers

Source: Internet
Author: User

Implement custom bullet box and mask layers and custom mask Layers

Sometimes we need to implement the Mask Layer Effect of our own pop-up box and pop-up box, next, let's talk about the javascript Implementation of the simplest of its own bullet box and the bullet box Mask Layer Effect. First, write the javascript of the mask layer. The Code is as follows:

1. Mask Layer js:

// Obtain coordinates
Function getPosition (){
Var top = document.doc umentElement. scrollTop;
Var left = document.doc umentElement. scrollLeft;
Var height = document.doc umentElement. clientHeight;
Var width = document.doc umentElement. clientWidth;
// Top = 500;
Left = 500;
// Height = 0;
Length = 500;
Height = 300;
Top = 300;
Return {top: top, left: left, height: height, width: width };
}
// Mask the input.
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 the mask
Function hideMask (id ){
Document. getElementById (id). style. display = "none ";
}
// Display the dialog box
Function showPop (id ){
ShowMask ('mask ');
Var width = 300; // The width of the pop-up box
Var height = 250; // The height of the pop-up 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 ";
};

}
// Implicit
Function hidePop (id ){
HideMask ('mask ');
Document. getElementById (id). style. display = "none ";
}

The html of the mask layer and bullet box is as follows:

<Input type = "button" value = "pop-up box" onclick = "showPop ('tcc')"/>

<! -- Mengban -->
<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>
<! -- Mengban end -->
<! -- Pop-up layer ---->
<Div id = "tcc" style = "display: none; background-color: #00 ffff; z-index: 201;">
<Input type = "button" value = "hide the pop-up layer" onclick = "hidePop ('tcc')"/>
</Div>

With the above effects, we can create custom bullet boxes, and the content of the bullet boxes can also be customized.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.