码迷,mamicode.com
首页 > 其他好文 > 详细

遮罩层、弹出层

时间:2015-12-04 14:42:45      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

1、实现原理
* 实际上弹出层、遮罩层和原页面显示分别为三个不同的div
* 弹出层的层级在遮罩层之上,遮罩层的层级在原页面显示之上;
* 遮罩层有通明效果
* 遮罩层没有实际意义,则无需在html部分就写上,当然写上同样可以实现

2、代码实现
html语言如下:

<body>
    <center>
        <div ><input type="button" value="go" onclick="show()"></div>
        <div id="alert" style="display:none;">
        <form>
            登录
            <input type="text"><input type="password"><input type="submit" value="login">
        </form>
        </div>
    </center>
</body>

javascript实现弹出层和遮罩层:

<span style="font-size:12px;"><script>function show(){
var alertPart=document.getElementById("alert");
alertPart.style.display="block";
alertPart.style.position = "absolute";
alertPart.style.top = "50%";
alertPart.style.left = "50%";
alertPart.style.marginTop = "-75px";
alertPart.style.marginLeft = "-150px";
alertPart.style.background="cyan";
alertPart.style.width="300px";
alertPart.style.height="200px";
alertPart.style.zIndex = "501";

var mybg = document.createElement("div");
mybg.setAttribute("id","mybg");
mybg.style.background = "#000";
mybg.style.width = "100%";
mybg.style.height = "100%";
mybg.style.position = "absolute";
mybg.style.top = "0";
mybg.style.left = "0";
mybg.style.zIndex = "500";
mybg.style.opacity = "0.3";
mybg.style.filter = "Alpha(opacity=30)";
document.body.appendChild(mybg);
document.body.style.overflow = "hidden";
}
</script></span>

遮罩层、弹出层

标签:

原文地址:http://www.cnblogs.com/fjptwwf/p/5019040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!