文章详细
js遮罩层
 2011/3/9 20:44:58 评论:1人 阅读次数:8950

直接贴代码了!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function BOX_show(e,a)//显示
{
    if (document.getElementById(e) == null) {
        return;
    }    
    if (!a) {
        var selects = document.getElementsByTagName('select');
        for (i = 0; i < selects.length; i++) {
            selects[i].style.visibility = "hidden";
        }
    }
    BOX_layout(e);
    window.onresize = function() { BOX_layout(e); } //改变窗体重新调整位置
    window.onscroll = function() { BOX_layout(e); } //滚动窗体重新调整位置
    document.onkeyup = function(event) {
        var evt = window.event || event;
        var code = evt.keyCode ? evt.keyCode : evt.which;
        //alert(code);

        if (code == 27) {
            BOX_remove(e);
        }
    }
}
function BOX_remove(e)//移除
{
    window.onscroll = null;
    window.onresize = null;
    document.getElementById('BOX_overlay').style.display = "none";
    document.getElementById(e).style.display = "none";

    var selects = document.getElementsByTagName('select');
    for (i = 0; i < selects.length; i++) {
        selects[i].style.visibility = "visible";
    }
}

function BOX_layout(e)//调整位置
{
    var a = document.getElementById(e);

    if (document.getElementById('BOX_overlay') == null)//判断是否新建遮掩层
    {

        var overlay = document.createElement("div");
        overlay.setAttribute('id', 'BOX_overlay');
        document.body.appendChild(overlay);
    }
    document.getElementById('BOX_overlay').ondblclick = function() { BOX_remove(e); };
    //取客户端左上坐标,宽,高
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);

    var clientWidth;
    if (window.innerWidth) {
        clientWidth = window.innerWidth;
    }
    else {
        clientWidth = document.documentElement.clientWidth;
    }    var clientHeight;
    if (window.innerHeight) {
        clientHeight = window.innerHeight;
    }
    else {
        clientHeight = document.documentElement.clientHeight;
    }    var bo = document.getElementById('BOX_overlay');
    bo.style.left = scrollLeft + 'px';
    bo.style.top = scrollTop + 'px';
    bo.style.width = '100%';
    bo.style.height = clientHeight + 'px';
    bo.style.display = 'block';

    //Popup窗口定位
    a.style.display = 'block'
    a.style.left = scrollLeft + ((clientWidth - a.offsetWidth) / 2) + 'px';
    a.style.top = scrollTop + ((clientHeight - a.offsetHeight) / 2) + 'px';
}

function HiddenButton(e) {
    e.style.visibility = 'hidden';
    e.previousSibling.style.visibility = 'visible'
}

function UserLogin(e) {
    BOX_show(e);
}
</script>
<style>
*{margin:0;padding:0;font-size:12px;font-style:normal;line-height:20px;}
html,body{height:100%;overflow:hidden;}
/**mask**/
#BOX_overlay {background:#000;left:0;filter:alpha(opacity=80);-moz-opacity:0.8; opacity: 0.8;position:absolute;top:0;z-index:100;}
/**iframe**/
div#layer_box{height:80%;width:80%;padding:30px 10px 10px;position:absolute;display:none;z-index:101;background:#fff url(bgimgconer_files/gradient.png);
}
</style>
</head>
<body>
<a href="javascript:UserLogin('layer_box');"><img src="brandPIC/BMW.png" />宝马</a>
<div id="layer_box">
	<iframe id="alls" name="alls" frameborder="0" scrolling="auto" src="http://www.86y.org" width="100%" height="100%"></iframe>
</div>
</body>
</html>
如需转载请注明出处:http://www.86y.org/art_detail.aspx?id=120【js遮罩层】幸凡学习网
0
 
相关文章
推荐文章
Created By Charry-May 3,2010
粤ICP备10093478号-1
顶部