治愈小屋
html 的部分:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>滑动切换页面</title>
<link rel="stylesheet" href="登录和注册页面切换.css">
</head>
<body>
<div class="container">
<div class="form">
<div class="register">
<h1>Register</h1>
<input type="text" placeholder="手机号">
<input type="email" placeholder="邮箱">
<input type="password" placeholder="密码">
<input type="password" placeholder="确认密码">
<button><a href="治愈系列.html">注册</a></button>
</div>
<div class="login hidden">
<h1>Login</h1>
<input type="text" placeholder="手机号或邮箱">
<input type="text" placeholder="用户名">
<input type="password" placeholder="密码">
<button><a href="治愈系列.html">登录</a></button>
</div>
</div>
<div class="back right">
<h2>欢迎来到<span>治愈小屋</span></h2>
<p>我在人间贩卖美好风景</p>
<em><img src="images/QQ图片20230315172650.jpg" width="150px" height="200px"></em>
<a>已有帐号?</a>
<button id="login1">去登录</button>
</div>
<div class="back left">
<h2>欢迎来到<span>治愈小屋</span></h2>
<p>我在人间贩卖美好风景</p>
<em><img src="images/QQ图片20230315172650.jpg" width="150px" height="200px"></em>
<a>没有帐号?</a>
<button id="register1">去注册</button>
</div>
css的部分:
*{
padding: 0;
margin: 0;
}
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: url("images/D6799F45C551901AB01E488BCD1E54D8.png") no-repeat;
/* background: linear-gradient(to right,#fceaea,#fcf2e8,#dfe3e2,#becfd3); */
}
.container{
background:rgb(255,255,255,.24);
width: 680px;
height: 415px;
border-radius: 5px;
box-shadow: 5px 5px 5px rgba(0,0,0,.1);
position:relative;
/* #e5b4be,#c898b0,#929dbe,#78b0ce */
}
.form{
position: absolute;
top: -17px;
left: 5%;
background:#a6bce8;
width: 320px;
height: 450px;
border-radius: 5px;
box-shadow: 2px 0 10px rgba(0,0,0,.1);
justify-content: center;
align-items: center;
display: flex;
z-index: 2;
transition: 0.5s ease-in-out;
}
.register,
.login{
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.hidden{
display: none;
transition:0.5s;
}
h1{
text-align: center;
margin-bottom: 20px;
text-transform: uppercase;
color:#fff;
letter-spacing: 5px;
}
input{
background-color: transparent;
width: 274px;
border: none;
outline: none;
color:#fff;
font-size:18px;
text-indent:10px;
margin:10px 0;
padding: 10px 0;
border-bottom: 1px solid rgba(0, 0, 0, .3);
}
input::placeholder{
color: #fff;
}
input:focus{
color: rgb(148, 138, 220);
border-bottom: 1px solid #fcf2e8;
}
input:focus::placeholder{
opacity: 0;
}
.form button{
width: 100px;
font-size: large;
letter-spacing: 5px;
margin-top: 21px;
border-radius: 5px;
border: none;
outline: none;
color:#9d87ea;
background-color:#Fff;
padding: 5px;
}
.form a{
text-decoration: none;
color:#9d87ea;
}
.form button:hover{
color: #f6f6f6;
background:linear-gradient(to right,#fceaea,#fcf2e8,#dfe3e2);
transition: background-color 0.5s ease;
}
.back{
width: 320px;
display:flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
top: 200px;
transform: translateY(-50%);
}
.back.left{
left:-2%;
}
.back.right{
right: -2%;
}
.back h2{
color:#8e99af;
font-size:25px;
font-weight: bold;
letter-spacing: 2px;
text-align: center;
margin-bottom: 4px;
}
.back span{
color:rgb(148, 138, 220);
}
.back p{
color:#a3aec5;
font-size:17px;
letter-spacing: 2px;
text-align: center;
}
.back em{
height: 240px;
}
.back img{
margin-top: 20px;
}
.back a{
font-style: italic;
color:skyblue;
}
.back button{
color:#9d87ea;
background-color: #fff;
border-radius: 10px;
width: 90px;
padding: 5px 3px;
border: none;
outline: none;
border:1px solid #ccc;
letter-spacing: 3px;
font-size: 18px;
}
script的部分:
<script>
var login1=document.getElementById('login1');
var register1=document.getElementById('register1');
var form = document.querySelector('.form');
var login=document.querySelector('.login');
var register = document.querySelector('.register');
login1.addEventListener('click',function(){
form.style.transform= 'translateX(90%)';
register.classList.add('hidden');
login.classList.remove('hidden');
form.style.backgroundColor='#a39fdb';
register1.style.color='#a6bce8';
})
register1.addEventListener('click',function(){
form.style.transform= 'translateX(0%)';
login.classList.add('hidden');
register.classList.remove('hidden');
form.style.backgroundColor='#859ed0';
})
</script>