div 模式窗体

<!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=utf-8" />
<title>无标题文档</title>
<style>
#mbDIV
{
position: absolute;
top: 0px;
left: 0px;
width:expression(screen.width+"px"); /*获得浏览器的宽度 document.body.clientWidth也可以*/
height:expression(screen.height+"px"); /*获得浏览器的宽度 document.body.clientHeight也可以*/
background-color: #AAAAAA;
z-index: 30;
filter: alpha(opacity=50);
}
#loginDIV
{
position: absolute;
width: 500px;
height: 180px;
background-color:white;
z-index: 40;
}
#loginTopDIV
{
width: 100%;
height: 22px;
text-align:center;
background-color: blue;
cursor: move;
}
</style>

</head>

<body>
<div id="mbDIV" style="display: none;"></div><!--遮盖层-->
<div id="loginDIV" style="display: none; left: 300px; top: 200px">
<div id="loginTopDIV">div模式窗体</div>
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="center" colspan="2">这里就对话框中的内容,且支持拖动功能,欢迎测试! </td>
</tr>
<tr>
<td align="center"><input οnclick="closeDIV()" type="button" value="关闭"> </td>
</tr>
</table>
</div>
<div align="center"><input οnclick="openDIV()" type="button" value="测试DIV模拟showModalDialog对话框"> </div>

<script>
function show(ele)
{
document.getElementById(ele).style.display="block";
}
function hidden(ele)
{
document.getElementById(ele).style.display="none";
}
function closeDIV()
{
hidden("loginDIV");
hidden("mbDIV");
}
function openDIV()
{
show("loginDIV");
show("mbDIV");
}
var mbDIV = document.getElementById("mbDIV");;
var loginDIV = document.getElementById("loginDIV");
var loginTopDIV = document.getElementById("loginTopDIV");

/**
*这里写的是拖动信息
* */
loginTopDIV.onmousedown = Down;
var tHeight,lWidth;
function Down(e)
{
var event = window.event || e;
tHeight = event.clientY - parseInt(loginDIV.style.top.replace(/px/,""));
lWidth = event.clientX - parseInt(loginDIV.style.left.replace(/px/,""));
document.onmousemove = Move;
document.onmouseup = Up;
}
function Move(e) {
var event = window.event || e;
var top = event.clientY - tHeight;
var left = event.clientX - lWidth;
//判断 top 和 left 是否超出边界
top = top < 0 ? 0 : top;
top = top > screen.height - 150 ? screen.height - 150 : top;
left = left < 0 ? 0 : left;
left = left >screen.width- 300 ?screen.width - 300 : left;
loginDIV.style.top = top + "px";
loginDIV.style.left = left +"px";
}
function Up() {
document.onmousemove = null;
}


</script>


</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值