Home >Web Front-end >JS Tutorial >The background of the pop-up layer implemented by javascript is grayed out - simulation (easyui dialog)_javascript skills
The background of the pop-up layer implemented by javascript is grayed out - simulation (easyui dialog)_javascript skills
WBOYOriginal
2016-05-16 17:06:301326browse
The page is rather ugly and only functions are implemented. ^ ^
Imitate the effect of easyui dialog< ;/title> <script> <br>//Get the page element<br>var getElement = function() { <br>return document.getElementById(arguments[0]) || false; <br>} <br>function openDialog(dialogId) { <br>var maskId = "mask"; <br>//If there is one, delete the original one first <br>if (getElement(dialogId)) { <br>document.removeChild(getElement (dialogId));//Delete operation: pop-up div <br>} <br>if (getElement(maskId)) { <br>document.removeChild(getElement(maskId));//Delete operation: pop-up inoperable (Mask) layer<br>} <br><br>//Grey background<br>var maskDiv = document.createElement("div"); <br>maskDiv.id = maskId; <br>maskDiv.style. position = "absolute"; <br>maskDiv.style.zIndex = "1"; <br>maskDiv.style.width = document.body.scrollWidth "px"; <br>maskDiv.style.height = document.body. scrollHeight "px"; <br>maskDiv.style.top = "0px"; <br>maskDiv.style.left = "0px"; <br>maskDiv.style.background = "gray"; <br>maskDiv.style .filter = "alpha(opacity=10)"; <br>maskDiv.style.opacity = "0.30";//Transparency<br>document.body.appendChild(maskDiv);//Add a background layer to the body<br><br>//Dialog <br>var dialogDiv = document.createElement("div"); <br>dialogDiv.id = dialogId; <br>dialogDiv.style.position = "absolute"; <br>dialogDiv. style.zIndex = "9999"; <br>dialogDiv.style.width = "400px"; <br>dialogDiv.style.height = "200px"; <br>dialogDiv.style.top = (parseInt(document.body. scrollHeight) - 200) / 2 "px"; // Center the screen <br>dialogDiv.style.left = (parseInt(document.body.scrollWidth) - 400) / 2 "px"; // Center the screen <br>dialogDiv .style.background = "white"; <br>dialogDiv.style.border = "1px solid gray"; <br>dialogDiv.style.padding = "5px"; <br>dialogDiv.innerHTML = "(Dialog Content)" ; <br>//Close operation in Dialog: close the background layer and Dialog layer <br>var closeControlloer = document.createElement("a");//Create a hyperlink (as a trigger for closing) <br> closeControlloer.href = "#"; <br>closeControlloer.innerHTML = "Close"; <br>closeControlloer.onclick = function() { <br>document.body.removeChild(getElement(dialogId));//Delete diaglog <br>document.body.removeChild(getElement(maskId));//Remove the background layer<br>} <br>dialogDiv.appendChild(closeControlloer);//Add "close" operation to the dialog<br>document.body. appendChild(dialogDiv);//Add dialog in body <br>} <br></script> Open Dialog< ;/a>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn