- 思路:就是把登陆窗放在界面之外,然后通过script内的函数改变到界面之内!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的登录窗体</title>
<style>
.loginDiv{
border: solid red 3px;
border-radius: 10px;
width: 350px;
height: 250px;
background-color: skyblue;
position: absolute;
top: -300px;
}
button{
border-radius: 3px;
}
#closeDiv{
position: relative;
top: -160px;
left: 305px;
}
</style>
</head>
<body>
<a href="javaScript:login()">登录窗</a>
<div class="loginDiv" id="loginDiv">
<h2 align="center">登录窗口</h2>
<table align="center">
<tr>
<th>用户名:</th>
<th><input type="text"></th>
</tr>
<tr>
<th>密码:</th>
<th><input type="password"></th>
</tr>
<tr>
<th colspan="2">
<button>登录</button> 
<button type="reset">重置</button>
</th>
</tr>
</table>
<div id="closeDiv"><a href="javaScript:close()">[关闭]</a></div>
</div>
<script>
function login() {
let loginDivObj = document.getElementById("loginDiv");
loginDivObj.style.top="100px";
loginDivObj.style.transition="top 600ms linear 500ms";
}
function close() {
let loginDivObj = document.getElementById("loginDiv");
loginDivObj.style.top="-300px";
}
</script>
</body>
</html>