首页 > web前端 > js教程 > javascript实现的弹出层背景置灰-模拟(easyui dialog)_javascript技巧

javascript实现的弹出层背景置灰-模拟(easyui dialog)_javascript技巧

WBOY
发布: 2016-05-16 17:06:30
原创
1340 人浏览过

页面比较丑,只把功能实现了。^ ^

复制代码 代码如下:

模仿easyui dialog的效果
<script> <br>//取得页面元素 <br>var getElement = function() { <br>return document.getElementById(arguments[0]) || false; <br>} <br>function openDialog(dialogId) { <br>var maskId = "mask"; <br>//如果有,先删除原来的 <br>if (getElement(dialogId)) { <br>document.removeChild(getElement(dialogId));//删除操作:弹出的div <br>} <br>if (getElement(maskId)) { <br>document.removeChild(getElement(maskId));//删除操作:弹出的不可操作(面具)层 <br>} <br><br>//背景置灰 <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";//透明度 <br>document.body.appendChild(maskDiv);//向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"; // 屏幕居中 <br>dialogDiv.style.left = (parseInt(document.body.scrollWidth) - 400) / 2 "px"; // 屏幕居中 <br>dialogDiv.style.background = "white"; <br>dialogDiv.style.border = "1px solid gray"; <br>dialogDiv.style.padding = "5px"; <br>dialogDiv.innerHTML = "(Dialog Content)"; <br>//Dialog之中的关闭操作:关闭背景层和Dialog层 <br>var closeControlloer = document.createElement("a");//创建一个超链接(做为关闭的触发) <br>closeControlloer.href = "#"; <br>closeControlloer.innerHTML = "关闭"; <br>closeControlloer.onclick = function() { <br>document.body.removeChild(getElement(dialogId));//删除diaglog <br>document.body.removeChild(getElement(maskId));//删除背景层 <br>} <br>dialogDiv.appendChild(closeControlloer);//dialog之中增加"关闭"操作 <br>document.body.appendChild(dialogDiv);//body之中增加dialog <br>} <br></script>
Open Dialog

javascript实现的弹出层背景置灰-模拟(easyui dialog)_javascript技巧
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板