本篇文章是對使用js實現遮罩以及彈出可移動登錄窗口的實現方法進行了詳細的分析介紹
需要的朋友參考下
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "
//W
C//DTD XHTML
Transitional//EN" "
<html xmlns="
<head>
<title></title>
<script type="text/javascript">
function showLogin() {
var loginDiv = document
getElementById("loginDiv");
var zhezhao = document
getElementById("zhezhao");
var clientx = document
documentElement
clientWidth;
var clienty = document
documentElement
clientHeight;
var l_margin = (clientx
parseInt(loginDiv
style
width)) /
;
var t_margin = (clienty
parseInt(loginDiv
style
height)
) /
loginDiv
style
left = l_margin + "px";
loginDiv
style
top = t_margin +"px";
loginDiv
style
display = "block";
zhezhao
style
display = "block";
}
function hidLogin() {
var loginDiv = document
getElementById("loginDiv");
var zhezhao = document
getElementById("zhezhao");
loginDiv
style
display = "none";
zhezhao
style
display = "none";
}
function titleMove() {
var moveable = true;
var loginDiv = document
getElementById("loginDiv");
//以下變量提前設置好 var clientX = window
event
clientX;
var clientY = window
event
clientY;
var moveTop = parseInt(loginDiv
style
top);
var moveLeft = parseInt(loginDiv
style
left);
document
onmousemove = function MouseMove() {
if (moveable) {
var y = moveTop + window
event
clientY
clientY;
var x = moveLeft + window
event
clientX
clientX;
if (x >
&& y >
) {
loginDiv
style
top = y + "px";
loginDiv
style
left = x + "px";
}
}
}
document
onmouseup = function Mouseup() {
moveable = false;
}
}
</script>
</head>
<body>
<!
Main start z
index:
>
<div id="Main" style="position:absolute;z
index:
;">
<a href="javascript:showLogin()">登陸</a>
</div>
<!
Main start z
index:
>
<!
loginDiv start :z
index:
>
<div id="loginDiv" style="background
color:white;width:
px;height:
px;border:
px solid blue;z
index:
;display:none;position:absolute;border
top:none">
<div onmousedown="titleMove()" id="login_title" style="width:
px;height:
px;background
color:Blue;border:
px solid silver;border
left:none;border
right:none">
<!
<img src="
/images/close
jpg" style="float:right" onclick="hidLogin()"/>
>
<a href="javascript:hidLogin()" style="float:right;text
decoration:none;color:white;margin
right:
px;font
size:
px">×</a>
</div>
<table style="clear:right;width:
px;height:
px;text
align:right;margin
top:
px;">
<tr><td>用戶名
</td><td><input type="text" style="width:
px;" /></td><td> </td></tr>
<tr><td>密碼:</td><td><input type="text" style="width:
px;" /></td><td> </td></tr>
<tr><td><br /></td><td></td></tr>
</table>
</div>
<!
loginDiv end :z
index:
>
<!
zhezhao start: z
index:
>
<div id="zhezhao" style="position:absolute;z
index:
;width:
%;height:
%;background
color:silver;display:none;opacity:
;">
<!
zhezhao end
>
</div>
</body>
</html>
【效果】
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19925.html