JavaScript-implemented pop-up-layer background grey-Simulation (Easyui dialog) _javascript tips

Source: Internet
Author: User
The page is ugly, only to achieve the function. ^ ^
Copy Code code as follows:

<title> imitate the effect of Easyui dialog </title>
<script>
Get page elements
var getelement = function () {
return document.getElementById (arguments[0]) | | False
}
function OpenDialog (dialogid) {
var maskid = "Mask";
If so, first delete the original
if (GetElement (dialogID)) {
Document.removechild (GetElement (dialogID));//delete action: Popup div
}
if (GetElement (Maskid)) {
Document.removechild (GetElement (Maskid));//delete operation: Eject non-operation (mask) layer
}

Background ash
var maskdiv = document.createelement ("div");
Maskdiv.id = Maskid;
MaskDiv.style.position = "absolute";
MaskDiv.style.zIndex = "1";
MaskDiv.style.width = document.body.scrollWidth + "px";
MaskDiv.style.height = document.body.scrollHeight + "px";
MaskDiv.style.top = "0px";
MaskDiv.style.left = "0px";
MaskDiv.style.background = "Gray";
MaskDiv.style.filter = "Alpha (opacity=10)";
maskDiv.style.opacity = "0.30";//Transparency
Document.body.appendChild (MASKDIV)//Add background layer to body

Dialog
var dialogdiv = document.createelement ("div");
Dialogdiv.id = dialogID;
DialogDiv.style.position = "absolute";
DialogDiv.style.zIndex = "9999";
DialogDiv.style.width = "400px";
DialogDiv.style.height = "200px";
DialogDiv.style.top = (parseint (document.body.scrollHeight)-2 + "px"; Center screen
DialogDiv.style.left = (parseint (document.body.scrollWidth)-)/2 + "px"; Center screen
DialogDiv.style.background = "White";
DialogDiv.style.border = "1px solid gray";
dialogDiv.style.padding = "5px";
dialogdiv.innerhtml = "(Dialog Content)";
Close operation in dialog: Close Background and dialog layers
var closecontrolloer = document.createelement ("a");//Create a hyperlink (as a shutdown trigger)
Closecontrolloer.href = "#";
closecontrolloer.innerhtml = "Close";
Closecontrolloer.onclick = function () {
Document.body.removeChild (GetElement (dialogID));//Delete Diaglog
Document.body.removeChild (GetElement (Maskid));//delete background layer
}
Dialogdiv.appendchild (closecontrolloer); add "close" action in//dialog
Document.body.appendChild (dialogdiv);//body Increase Dialog
}
</script>
<a href= "#" onclick= "OpenDialog (' dialog ');" >open dialog</a>

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.