JS蒙板弹出+关闭


function showMenu(content) {
// 创建蒙板DIV
var bgObj = document.createElement("div");
// 蒙板样式
bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:100%;"
+ "height:100%;filter:Alpha(Opacity=30);opacity:0.3;"
+ "background-color:#000000;z-index:101;";
// 使用蒙板
document.body.appendChild(bgObj);
// 创建菜单栏
var menuDiv = document.createElement("div");
// 菜单栏样式
menuDiv.style.cssText = "width: 540px;height: 262px;position: absolute;"
+ "top: 30%;left: 50%;margin: -131px 0 0 -270px"
+ ";text-align:center;background-color:white;padding:1px;line-height:22px;z-index:102;";
// 使用菜单栏
document.body.appendChild(menuDiv);
var top = getPos(menuDiv)[0] - 10;
var left = getPos(menuDiv)[1] + 520;
// 创建关闭按钮
var closeBtn = document.createElement("img");
closeBtn.onclick = function() {
document.body.removeChild(bgObj);
document.body.removeChild(menuDiv)
document.body.removeChild(closeBtn);
};
closeBtn.id = "closeBtn";
// 关闭按钮样式
closeBtn.style.cssText = "height:31px;width:31px;display:block;z-index:103;position:absolute;"
+ "top:" + top + ";left:" + left + ";cursor: pointer;";
// 填充关闭按钮内容
closeBtn.src = "Images/Main/closeImg.png";
// 使用关闭按钮
document.body.appendChild(closeBtn);
// 填充菜单栏内容
menuDiv.innerHTML = content;
function getEvent() {
return window.event || arguments.callee.caller.arguments[0];
}
}

//获取控件绝对位置
function getPos(active) {
var t = active.offsetTop;
var l = active.offsetLeft;
while (active = active.offsetParent) {
t += active.offsetTop;
l += active.offsetLeft;
}
return new Array(t,l);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值