Javascript implementation of pop up layer background ash simulate of easyui dialog
- 2020-03-30 01:06:05
- OfStack
The page is ugly, only to achieve the function. ^ ^
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201312/201312271135362.gif? 20131127113551 ">
<title> imitation easyui dialog The effect of </title>
<script>
//Get page elements
var getElement = function() {
return document.getElementById(arguments[0]) || false;
}
function openDialog(dialogId) {
var maskId = "mask";
//If so, delete the original
if (getElement(dialogId)) {
document.removeChild(getElement(dialogId));//Delete: div pops up
}
if (getElement(maskId)) {
document.removeChild(getElement(maskId));//Delete operation: popup non - operational (mask) layer
}
//Background grey
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 a background layer to the 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) - 200) / 2 + "px"; //Center of the screen
dialogDiv.style.left = (parseInt(document.body.scrollWidth) - 400) / 2 + "px"; //Center of the screen
dialogDiv.style.background = "white";
dialogDiv.style.border = "1px solid gray";
dialogDiv.style.padding = "5px";
dialogDiv.innerHTML = "(Dialog Content)";
//Close in Dialog: close the background and Dialog layers
var closeControlloer = document.createElement("a");//Create a hyperlink (as a closing trigger)
closeControlloer.href = "#";
closeControlloer.innerHTML = " Shut down ";
closeControlloer.onclick = function() {
document.body.removeChild(getElement(dialogId));//Delete diaglog
document.body.removeChild(getElement(maskId));//Delete background layer
}
dialogDiv.appendChild(closeControlloer);//Add a close operation to dialog
document.body.appendChild(dialogDiv);//Add dialog to the body
}
</script>
<a href="#" onclick="openDialog('dialog');">Open Dialog</a>
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201312/201312271135362.gif? 20131127113551 ">