<!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>demo</title>
<style>
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;}
body,button,input,select,textarea{font:12px/1.5 tahoma,arial,\5b8b\4f53;}
h1,h2,h3,h4,h5,h6{font-size:100%;}
address,cite,dfn,em,
var
{font-style:normal;}
code,kbd,pre,samp{font-family:courier
new
,courier,monospace;}
small{font-size:12px;}
ul,ol{list-style:none;}
a{text-decoration:none;}
a:hover{text-decoration:underline;}
sup{vertical-align:text-top;}
sub{vertical-align:text-bottom;}
legend{color:#000;}
fieldset,img{border:0;}
button,input,select,textarea{font-size:100%;}
table{border-collapse:collapse;border-spacing:0;}
.clear{clear: both;float: none;height: 0;overflow: hidden;}
#btn{width: 80px;
height: 40px;
background: #3b7ae3;
margin:0 auto;
display: block;
cursor: pointer;
border-style: none;
color: #fff;
font-size: 16px;}
#mask{
background: #000;
opacity: 0.75;
filter: alpha(opacity=75);
height: 1000px;
width: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 1000;
}
#login{position: absolute; top: 100px; left: 100px; width: 400px; height: auto; border:1px solid #d5d5d5; z-index: 1001; }
.title{position: relative;background-color: #f7f7f7; cursor: move; height: 50px; line-height: 50px; font-size: 16px; color: #333; padding-left:30px;}
.close{position: absolute; top:0; right: 10px; color: #ccc;}
.content{background: #fff; padding: 15px 20px;}
.user{margin-bottom: 15px;}
.password{margin-bottom: 15px;}
.pt{display: block;
height: 38px;
padding-left: 15px;
border: 1px solid #ddd;
transition: .3s;
font-size: 14px;
color: #666;
width: 343px;
}
.sm{display: block;
height: 48px;
border: 1px solid #ddd;
transition: .3s;
font-size: 16px;
color: #666;
width: 360px;
background: #3b7ae3;
color: #fff;}
</style>
</head>
<body>
<!-- <div id=
"mask"
></div> -->
<button id=
"btn"
href=
""
>登录</button>
<!-- <div
class
=
"login"
id=
"login"
>
<div
class
=
"title"
id=
"title"
>登录百度账号<a href=
"#"
class
=
"close"
>x</a></div>
<div
class
=
"content"
>
<div
class
=
"user"
><input
class
=
"pt"
type=
"input"
value=
"手机/邮箱/用户名"
></div>
<div
class
=
"password"
><input
class
=
"pt"
type=
"input"
value=
"密码"
></div>
<div
class
=
"submit"
><input
class
=
"sm"
type=
"submit"
value=
"登录"
></div>
</div>
</div> -->
<script type=
"text/javascript"
>
function
b(){
var
mask=document.createElement(
"div"
);
mask.id=
"mask"
;
mask.style.height=cheight+
"px"
;
document.body.appendChild(mask);
var
login=document.createElement(
"div"
);
login.id=
"login"
;
login.innerHTML='<div
class
=
"title"
id=
"title"
>登录百度账号'+'<a href=
"#"
class
=
"close"
>x</a>'+'</div>'+
'<div
class
=
"content"
>'+'<div
class
=
"user"
>'+'<input
class
=
"pt"
type=
"input"
value=
"手机/邮箱/用户名"
>'+'</div>'+'<div
class
=
"password"
>'+'<input
class
=
"pt"
type=
"input"
value=
"密码"
>'+'</div>'+'<div
class
=
"submit"
>'+'<input
class
=
"sm"
type=
"submit"
value=
"登录"
>'+'</div>'+'</div>';
document.body.appendChild(login);
var
cwidth= document.documentElement.clientWidth || document.body.clientWidth;
var
cheight= document.documentElement.clientHeight || document.body.clientHeight;
var
lwidth=login.offsetWidth;
var
lheight=login.offsetHeight;
login.style.left=(cwidth-lwidth)/2+
"px"
;
login.style.top=(cheight-lheight)/2+
"px"
;
mask.style.height=cheight+
"px"
;
window.onresize=
function
(){
if
(document.compatMode==
"CSS1Compat"
){
cwidth=document.documentElement.clientWidth;
cheight=document.documentElement.clientHeight;
}
else
{
cwidth=document.body.clientWidth;
cheight=document.body.clientHeight;
}
login.style.left=(cwidth-lwidth)/2+
"px"
;
login.style.top=(cheight-lheight)/2+
"px"
;
mask.style.height=cheight+
"px"
;
}
var
title=document.getElementById(
"title"
);
var
isDraging=false;
var
mouseOffsetX;
var
mouseOffsetY;
title.onmousedown=
function
(e){
var
e=e||window.event;
mouseOffsetX=e.pageX-login.offsetLeft;
mouseOffsetY=e.pageY-login.offsetTop;
isDraging=true;
}
document.onmousemove=
function
(e){
var
e=e||window.event;
var
newMX=e.pageX;
var
newMY=e.pageY;
if
(isDraging===true){
var
loginL=newMX-mouseOffsetX;
var
loginT=newMY-mouseOffsetY;
if
(loginL<0){
loginL=0;
}
else
if
(loginL>(cwidth-lwidth)){
loginL=cwidth-lwidth;
}
if
(loginT<0){
loginT=0;
}
else
if
(loginT>(cheight-lheight)){
loginT=cheight-lheight;
}
login.style.left=loginL+
"px"
;
login.style.top=loginT+
"px"
;
}
}
document.onmouseup=
function
(){
isDraging=false;
}
var
close=login.getElementsByClassName(
"close"
)[0];
close.onclick=
function
(){
document.body.removeChild(mask);
document.body.removeChild(login);
}
}
window.onload=
function
(){
var
btn=document.getElementById(
"btn"
);
btn.onclick=
function
(){
b();
}
}
</script>
</body>
</html>