写在前面
注册登录组件,是我们在实际开发中经常会用到的一个基础组件,在之前的练习中,我们也分享过很多在不同产品上的实现效果。
当然,更多的还是个人用户在各大平台终端上的组件应用。
它会因为业务,场景,需求的不同,从而开发设计也会不太一样,但是就目前的开发来讲,差异都不是很大,当然,在遇见实际场景时,可以再具体问题具体分析。
因此,今天我们还是来看一个比较通用的效果,具体效果如下:
HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>【每日一练】123—一组注册登录表单组件</title>
<link rel="stylesheet" href="css/reset.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="form">
<div class="form-toggle"></div>
<div class="form-panel one">
<div class="form-header">
<h1>会员登录</h1>
</div>
<div class="form-content">
<form>
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" required="required"/>
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required="required"/>
</div>
<div class="form-group">
<label class="form-remember">
<input type="checkbox"/>记住密码
</label><a class="form-recovery" href="#">忘记密码?</a>
</div>
<div class="form-group">
<button type="submit">登录</button>
</div>
</form>
</div>
</div>
<div class="form-panel two">
<div class="form-header">
<h1>会员注册</h1>
</div>
<div class="form-content">
<form>
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" required="required"/>
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required="required"/>
</div>
<div class="form-group">
<label for="cpassword">确认密码</label>
<input type="password" id="cpassword" name="cpassword" required="required"/>
</div>
<div class="form-group">
<label for="email">邮箱</label>
<input type="email" id="email" name="email" required="required"/>
</div>
<div class="form-group">
<button type="submit">注册</button>
</div>
</form>
</div>
</div>
</div>
<script src='js/jquery.min.js'></script>
<script src="js/script.js"></script>
</body>
</html>
CSS代码:
html {
width: 100%;
height: 100%;
}
body {
background: #00a6bc;
color: rgba(0, 0, 0, 0.6);
font-family: "Roboto", sans-serif;
font-size: 14px;
line-height: 1.6em;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.overlay, .form-panel.one:before {
position: absolute;
top: 0;
left: 0;
display: none;
background: #00a6bc;
width: 100%;
height: 100%;
}
.form {
z-index: 15;
position: relative;
background: #FFFFFF;
width: 600px;
border-radius: 4px;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
box-sizing: border-box;
margin: 100px auto 10px;
overflow: hidden;
}
.form-toggle {
z-index: 10;
position: absolute;
top: 60px;
right: 60px;
background: #FFFFFF;
width: 60px;
height: 60px;
border-radius: 100%;
transform-origin: center;
transform: translate(0, -25%) scale(0);
opacity: 0;
cursor: pointer;
transition: all 0.3s ease;
}
.form-toggle:before, .form-toggle:after {
content: "";
display: block;
position: absolute;
top: 50%;
left: 50%;
width: 30px;
height: 4px;
background: #00a6bc;
transform: translate(-50%, -50%);
}
.form-toggle:before {
transform: translate(-50%, -50%) rotate(45deg);
}
.form-toggle:after {
transform: translate(-50%, -50%) rotate(-45deg);
}
.form-toggle.visible {
transform: translate(0, -25%) scale(1);
opacity: 1;
}
.form-group {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin: 0 0 20px;
}
.form-group:last-child {
margin: 0;
}
.form-group label {
display: block;
margin: 0 0 10px;
color: rgba(0, 0, 0, 0.6);
font-size: 12px;
font-weight: 500;
line-height: 1;
text-transform: uppercase;
letter-spacing: 0.2em;
}
.two .form-group label {
color: #FFFFFF;
}
.form-group input {
outline: none;
display: block;
background: rgba(0, 0, 0, 0.1);
width: 100%;
border: 0;
border-radius: 4px;
box-sizing: border-box;
padding: 12px 20px;
color: rgba(0, 0, 0, 0.6);
font-family: inherit;
font-size: inherit;
font-weight: 500;
line-height: inherit;
transition: 0.3s ease;
}
.form-group input:focus {
color: rgba(0, 0, 0, 0.8);
}
.two .form-group input {
color: #FFFFFF;
}
.two .form-group input:focus {
color: #FFFFFF;
}
.form-group button {
outline: none;
background: #444;
width: 100%;
border: 0;
border-radius: 4px;
padding: 12px 20px;
color: #FFFFFF;
font-family: inherit;
font-size: inherit;
font-weight: 500;
line-height: inherit;
text-transform: uppercase;
cursor: pointer;
}
.two .form-group button {
background: #FFFFFF;
color: #00a6bc;
}
.form-group .form-remember {
font-size: 12px;
font-weight: 400;
letter-spacing: 0;
text-transform: none;
}
.form-group .form-remember input[type=checkbox] {
display: inline-block;
width: auto;
margin: 0 10px 0 0;
}
.form-group .form-recovery {
color: #00a6bc;
font-size: 12px;
text-decoration: none;
}
.form-panel {
padding: 60px calc(5% + 60px) 60px 60px;
box-sizing: border-box;
}
.form-panel.one:before {
content: "";
display: block;
opacity: 0;
visibility: hidden;
transition: 0.3s ease;
}
.form-panel.one.hidden:before {
display: block;
opacity: 1;
visibility: visible;
}
.form-panel.two {
z-index: 5;
position: absolute;
top: 0;
left: 95%;
background: #444;
width: 100%;
min-height: 100%;
padding: 60px calc(10% + 60px) 60px 60px;
transition: 0.3s ease;
cursor: pointer;
}
.form-panel.two:before, .form-panel.two:after {
content: "";
display: block;
position: absolute;
top: 60px;
left: 1.5%;
background: rgba(255, 255, 255, 0.2);
height: 30px;
width: 2px;
transition: 0.3s ease;
}
.form-panel.two:after {
left: 3%;
}
.form-panel.two:hover {
left: 93%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.form-panel.two:hover:before, .form-panel.two:hover:after {
opacity: 0;
}
.form-panel.two.active {
left: 10%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
cursor: default;
}
.form-panel.two.active:before, .form-panel.two.active:after {
opacity: 0;
}
.form-header {
margin: 0 0 40px;
}
.form-header h1 {
padding: 4px 0;
color: #444;
font-size: 24px;
font-weight: 700;
text-transform: uppercase;
}
.two .form-header h1 {
position: relative;
z-index: 40;
color: #FFFFFF;
}
.pen-footer {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 600px;
margin: 20px auto 100px;
}
.pen-footer a {
color: #FFFFFF;
font-size: 12px;
text-decoration: none;
text-shadow: 1px 2px 0 rgba(0, 0, 0, 0.1);
}
.pen-footer a .material-icons {
width: 12px;
margin: 0 5px;
vertical-align: middle;
font-size: 12px;
}
.cp-fab {
background: #FFFFFF !important;
color: #4285F4 !important;
}
JS代码:
$(document).ready(function() {
var panelOne = $('.form-panel.two').height(),
panelTwo = $('.form-panel.two')[0].scrollHeight;
$('.form-panel.two').not('.form-panel.two.active').on('click', function(e) {
e.preventDefault();
$('.form-toggle').addClass('visible');
$('.form-panel.one').addClass('hidden');
$('.form-panel.two').addClass('active');
$('.form').animate({
'height': panelTwo
}, 200);
});
$('.form-toggle').on('click', function(e) {
e.preventDefault();
$(this).removeClass('visible');
$('.form-panel.one').removeClass('hidden');
$('.form-panel.two').removeClass('active');
$('.form').animate({
'height': panelOne
}, 200);
});
});
完整源码下载地址:
https://url81.ctfile.com/f/21793581-761227049-009057?p=2698
访问密码: 2698
大家可以根据自己情况进行下载练习。
写在最后
以上就是每日一练的全部内容,希望今天的小练习对你有用,如果你觉得有帮助的话,请点赞我,关注我,并将它分享给你身边做开发的朋友,也许能够帮助到他。
我是杨小爱,我们明天见。
推荐阅读
学习更多技能
请点击下方公众号