js弹出DIV层

备忘。。

ContractedBlock.gifExpandedBlockStart.gifjs代码
ExpandedBlockStart.gifContractedBlock.gif/**//**
 * @author Administrator
 
*/


var ModalOpacity =0;
var th1;
var width =0;
var height=0;
var right,top;
var mousePos;
document.onmousemove 
= mouseMove;
function mouseMove(ev)
ExpandedBlockStart.gifContractedBlock.gif
{
    ev 
= ev || window.event;
    mousePos 
= mouseCoords(ev);
}


function mouseCoords(ev)
ExpandedBlockStart.gifContractedBlock.gif
{
    
if(ev.pageX || ev.pageY)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
return {x:ev.pageX, y:ev.pageY};
    }

    
return 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        x:ev.clientX 
+ document.body.scrollLeft - document.body.clientLeft
        y:ev.clientY 
+ document.body.scrollTop - document.body.clientTop
    }
;
}


function ShowModal(Type)
ExpandedBlockStart.gifContractedBlock.gif
{
    
switch(Type)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
case "login":ShowLogin();break;
        
case "regist":ShowRegist();break;
    }

}



function ShowLogin()
ExpandedBlockStart.gifContractedBlock.gif
{
    
var modal = document.getElementById('Modal');
    
if(modal.style.display == "block")
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
return false;
    }

    
    modal.style.display 
= "block";
    
    modal.onmousemove 
= mouseMove;
    
var e = window.event;
    
if(!document.all)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        right 
= document.body.clientWidth - mousePos.x+20;
        top 
= mousePos.y+10;
    }

    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        right 
= document.body.clientWidth - document.documentElement.scrollLeft - e.clientX +20;
        top 
= document.documentElement.scrollTop + e.clientY +10;
    }

    

    modal.style.right 
= right +"px";
    modal.style.top 
= top + "px";
    th1 
= setInterval("ShowLoginModal()",1);
}



function ShowLoginModal()
ExpandedBlockStart.gifContractedBlock.gif
{
    
var modal = document.getElementById('Modal');
    width 
+= 20;
    height 
+= 3;
    modal.style.width 
= width +"px";
    modal.style.height 
= height +"px";
    ModalOpacity 
+= 5;
    modal.style.filter
="Alpha(opacity="+ModalOpacity+")"//透明度逐渐变大
    modal.style.opacity = ModalOpacity/100; //兼容FireFox
    if(ModalOpacity > 100)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        document.getElementById(
'Form').style.display = "block";
        clearInterval(th1);
    }

}


function CloseDiv()
ExpandedBlockStart.gifContractedBlock.gif
{
    
var modal = document.getElementById('Modal');
    
var Form = document.getElementById('Form');
    modal.style.display 
= "none";
    modal.style.height 
= 0+"px";
    modal.style.width 
= 0+"px";
    modal.style.opacity 
= 0;
    Form.style.display 
= "none";
    height 
= 0;
    width 
= 0;
    ModalOpacity 
= 0;
    right 
= 0;
    top 
= 0;
}




 


ContractedBlock.gifhtml页面

ExpandedBlockStart.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
<title>javascript_test</title>
ExpandedBlockStart.gifContractedBlock.gif        
<style type="text/css">
            body
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{}{
                font-size
:14px;                            
                margin
:0;
                padding
:0;
            
}

ExpandedSubBlockStart.gifContractedSubBlock.gif            a
{}{
                margin-left
:15px;
            
}

ExpandedSubBlockStart.gifContractedSubBlock.gif            a:link,a:visited
{}{text-decoration:none;color:black;}
            a:hover
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{}{
                text-decoration
:underline;
                color
:red;
            
}

            #menu
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{}{
                float
:left;
                text-align
:right;
                padding
:10px 20px;
                width
:970px;
                line-height
:30px;                
            
}

            
            #Modal
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{}{
                position
:absolute;
                background-color
:#DFDFE1;
                z-index
:10000;
                border
:1px dotted red;
                filter
:alpha(opacity:0);
                opacity
:0;
                display
:none;
            
}

            #UserName,#UserPwd
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{}{
                width
:90px;
            
}

            #Form
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{}{
                margin-top
:20px;
                margin-left
:10px;
                display
:none;
            
}

        
</style>
        
<script type="text/javascript" language="JavaScript" src="OpenModal.js"></script>
    
</head>
    
<body>
        
<div id="menu">
            
<href="javascript:void(0)" onclick="ShowModal('login');">登陆</a>
            
<href="javascript:void(0)" onclick="ShowModal('regist');">注册</a>
        
</div>
        
<div id="Modal">
            
<div id="Form">
            用户名:
<input type="text" id="UserName" />密码:<input type="password" id="UserPwd" />
            
<input type="button" id="login" value="登陆" />
            
<input type="button" id="close" onclick="CloseDiv()" value="关闭" />
            
</div>
        
</div>
    
</body>
</html>

转载于:https://www.cnblogs.com/coolkiss/archive/2008/12/24/1361463.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值