-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.html
123 lines (114 loc) · 4.13 KB
/
dialog.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录页面</title>
<link rel="stylesheet" href="css/main.css" />
</head>
<body>
<div class="ui-dialog" id="dialog">
<div class="ui-dialog-title" id="dialogTitle">
<a href="javascript:haideDialog();" class="ui-dialog-closebutton"></a>
登录通行证
</div>
<form method="post" action="success.html">
<div class="ui-dialog-content">
<div class="ui-dialog-140 ui-dialog-pt15">
<input type="input" name="use" class="ui-dialog-input ui-dialog-input-username" placeholder="手机/邮箱/用户名" />
</div>
<div class="ui-dialog-140 ui-dialog-pt15">
<input type="password" name="pwd" class="ui-dialog-input ui-dialog-input-password" placeholder="密码" />
</div>
<div class="ui-dialog-140 interval">
<a href="#">忘记密码</a>
</div>
<div>
<a href="#" class="ui-dialog-submit">登录</a>
</div>
<div class="ui-dialog-140">
<a href="#">没有账号?立即注册</a>
</div>
</div>
</form>
</div>
<div id="mask" class="ui-mask" onslectstart="return false"></div>
<div class="link">
<a href="javascript:showDialog();">登录</a>
</div>
<script type="text/javascript">
// 获取元素对象
function g(id){
return document.getElementById(id);
}
// 自动居中-登录浮层(el=Element)
function autoCenter(el){
var bodyW=document.documentElement.clientWidth;
var bodyH=document.documentElement.clientHeight;
var elW=el.offsetWidth;
var elH=el.offsetHeight;
el.style.left=(bodyW-elW)/2+'px';
el.style.top=(bodyH-elH)/2+'px';
}
// 自动全屏-遮罩
function fillToBody(el){
el.style.width=document.documentElement.clientWidth + "px";
el.style.height=document.documentElement.clientHeight + "px";
}
var mouseoffsetX=0; //偏移
var mouseoffsetY=0;
var isdraing=false;
//鼠标事件1 -在标题栏上按下(要计算鼠标相对拖拽元素的左上角的坐标,并且标记元素为可拖动)
g('dialogTitle').addEventListener('mousedown',function(e){
var e=e||window.event;
mouseoffsetX=e.pageX-g('dialog').offsetLeft;
mouseoffsetY=e.pageY-g('dialog').offsetTop;
isdraing=true;
})
//鼠标事件2-鼠标移动时(要检测,元素是否可标记为可移动,如果是,则更新元素的位置,到当前鼠标的位置【ps:要减去第一步中获得的偏移】)
document.onmousemove=function(e){
var e=e||window.event;
var mouseX=e.pageX; //鼠标当前位置
var mouseY=e.pageY;
var moveX=0;
var moveY=0;
if (isdraing===true) {
moveX=mouseX-mouseoffsetX;
moveY=mouseY-mouseoffsetY;
//拖拽范围 moveX>0 moveX<页面宽度-登录层的宽度
// moveY>0 moveY<页面高度-登录层高度
var pageWidth=document.documentElement.clientWidth;
var pageHeight=document.documentElement.clientHeight;
var dialogWidth=g('dialog').offsetWidth;
var dialogHeight=g('dialog').offsetHeight;
var maxW=pageWidth-dialogWidth;
var maxH=pageHeight-dialogHeight;
moveX=Math.min(maxW,Math.max(0,moveX));
moveY=Math.min(maxH,Math.max(0,moveY));
g('dialog').style.left=moveX+'px';
g('dialog').style.top=moveY+'px';
}
}
//鼠标事件3-鼠标松开的时候(标记元素为不可拖动)
document.onmouseup=function(){
isdraing=false;
}
//展现登录浮层
function showDialog(){
g('dialog').style.display='block';
g('mask').style.display='block';
autoCenter(g('dialog'));
fillToBody(g('mask'));
}
//关闭登录浮层
function haideDialog(){
g('dialog').style.display='none';
g('mask').style.display='none';
}
//解决改变窗口大小不居中问题
window.onresize=function(){
autoCenter(g('dialog'));
fillToBody(g('mask'));
}
</script>
</body>
</html>