html点击按钮弹出窗口背景灰掉,点击背景变白退出点击退出也可以
(2011-06-10 18:22:23)
标签:
杂谈 |
function showid(idname){
var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE
(\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
var newbox=document.getElementByIdx_x(idname);
newbox.style.zIndex="9999";
newbox.style.display="block"
newbox.style.position = !isIE6 ? "fixed" : "absolute";
newbox.style.top =newbox.style.left = "50%";
newbox.style.marginTop = - newbox.offsetHeight / 2 + "px";
newbox.style.marginLeft = - newbox.offsetWidth / 2 + "px";
var layer=document.createElement_x("div");
layer.id="layer";
layer.style.width=layer.style.height="100%";
layer.style.position= !isIE6 ? "fixed" : "absolute";
layer.style.top=layer.style.left=0;
layer.style.backgroundColor="#000";
layer.style.zIndex="9998";
layer.style.opacity="0.6";
document.body.appendChild(layer);
function layer_iestyle(){
layer.style.width=Math.max(document.documentElement.scrollWidth,
document.documentElement.clientWidth)+ "px";
layer.style.height= Math.max(document.documentElement.scrollHeight,
document.documentElement.clientHeight) +"px";
}
function newbox_iestyle(){
newbox.style.marginTop = document.documentElement.scrollTop -
newbox.offsetHeight / 2 + "px";
newbox.style.marginLeft = document.documentElement.scrollLeft -
newbox.offsetWidth / 2 + "px";
}
if(isIE){layer.style.filter ="alpha(opacity=60)";}
if(isIE6){
layer_iestyle()
newbox_iestyle();
window.attachEvent("onscroll",function(){
newbox_iestyle();
})
window.attachEvent("onresize",layer_iestyle)
}
layer.onclick=function(){newbox.style.display="none";layer.style.display="none";document.body.removeChild(layer)}
}
function closelayer(){
上面是js,html是下面酱紫的
下面是隐藏部分
<div id="address-book"
style="display:none;">Address Book<br
/>
</div>

加载中…