透明遮罩层

在很多WEB开发的时候我们都需要用到透明遮罩层来实现某些功能。下面共享一下比较实用的代码;

 

JS代码:

<script language="javascript" type="text/javascript">
//创建一个遮罩层
function Layer(html)
{
//创建一个遮罩层,半透明
var lay = document.createElement("div");
lay.id = "frame"
with(lay.style)
{
width = "100%";
height = String(Math.max(document.documentElement.clientHeight,document.documentElement.scrollHeight))+"px";
background = "#000000";
position = "absolute";
left = "0";
top = "0";
filter = 'Alpha(opacity=70)';
opacity = '0.7';
}
document.body.appendChild(lay);
document.getElementById("frame").ondblclick = hiddenDiv;

//创建显示内容
var info = document.createElement("div");
info.id = "msg";
info.innerHTML = html;
document.getElementById("frame").appendChild(info);
with(info.style)
{
position = "absolute";
left = "0px";
top = document.documentElement.scrollTop + document.body.scrollTop + "px";
marginLeft = (document.documentElement.clientWidth - info.offsetWidth)/2 + "px";
marginTop = (document.documentElement.clientHeight - info.offsetHeight)/2 + "px";
}
document.body.appendChild(info);
}

//关闭遮罩层
function hiddenDiv(){document.body.removeChild(document.getElementById("frame"));document.body.removeChild(document.getElementById("msg"));}

function loadIndex(){
Layer("<b>Cawei</b>");
}
</script>

HMTL代码:

<body onload="loadIndex()">
<table><tr><td>伟博小城</td></tr><tr><td><select><option>www.webczw.com</option><option>遮罩层</option></select></td></tr></table>
</body>




转载于:https://www.cnblogs.com/webczw/archive/2012/02/07/2341636.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值