写项目时想要一个新颖的登录界面,在网上找到了个喜欢的,自己修改了一些东西,下面是借鉴的原视频连接
HTML5+CSS3小实例:不偷看密码的超萌猫头鹰登录界面_哔哩哔哩_bilibili
因为项目是保护海洋方面的,所以把猫头鹰替换成了海洋中的鲸鱼,下面是效果
在点击密码框时登录框上的小动物会自动捂住眼睛,密码框失去焦点后,手又放下
以下是实现代码
Html代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Login</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<link href="Content/bootstrap.css" rel="stylesheet" />
<link rel="stylesheet" href="CSS/bule.css">
<link href="CSS/home.css" rel="stylesheet" />
<script type="text/javascript">
var flag = false;//用来判断是否可以成功登录
var flag2 = false;
//验证手机号
function regPhone() {
var phone = document.getElementById("account").value;
var var5 = /0?(13|14|15|18|17|19)[0-9]{9}/; //手机号
if (!var5.test(phone)) {
document.getElementById("regPhone").innerText = "请输入手机号格式";
document.getElementById("regPhone").style.color = "#20b2aa";
flag = false;
} else {
flag = true;
document.getElementById("regPhone").innerText = "";
}
}
//验证密码
function regPwd() {
var pwd = document.getElementById("password").value;
var var2 = /^[A-Z]{1}[A-Za-z0-9]{7,9}$/; //密码
if (!var2.test(pwd)) {
//密码
document.getElementById("regPwd").innerText = "请输入大写字母开头、数字字母混合、8-10位";
document.getElementById("regPwd").style.color = "#20b2aa";
flag2 = false;
} else {
flag2 = true;
document.getElementById("regPwd").innerText = "";
}
}
//跳转页面
window.onload = function () {
var btn = document.getElementById("submit");
btn.onclick = function () {
if(flag && flag2){
window.open('index.html','_blank');
}
}
}
$(function () {
$('#password').focus(function () {
// 密码框获得焦点,追加样式.password
$('#owl').addClass('password');
}).blur(function () {
// 密码框失去焦点,移除样式.password
$('#owl').removeClass('password');
})
})
</script>
</head>
<body>
<video autoplay="autoplay" loop="loop" muted>
<source src="Video/Login.mp4" type="video/mp4" />
</video>
<div id="headmeun" class="headmeun">
<div class="centers">
<div id="logo">
<img src="Images/Logo.png" width="55" height="55" />
</div>
<div id="meun">
<ul>
<li>
<a href="index.html">首页</a>
<img src="Images/water.png" width="45" height="10" class="hover1" />
</li>
<li>
<a href="Evail.html">走近海博 </a>
<img src="Images/water.png" width="80" height="10" class="hover1" />
</li>
<li>
<a href="order.html">参观服务</a>
<img src="Images/water.png" width="80" height="10" class="hover1" />
</li>
<li>
<a href="Exhibits.html">陈列展览</a>
<img src="Images/water.png" width="80" height="10" class="hover1" />
</li>
<li>
<a href="Haiboroom.html">海博讲堂</a>
<img src="Images/water.png" width="80" height="10" class="hover1" />
</li>
<li>
<a href="News.html">海博新闻</a>
<img src="Images/water.png" width="80" height="10" class="hover1" />
</li>
</ul>
</div>
<div id="function">
<ul>
<li class="glyphicon glyphicon-search"></li>
<a href="login.html">
<li class="glyphicon glyphicon-user"></li>
</a>
</ul>
</div>
</div>
</div>
<div class="back">
<div class="login-box">
<div class="owl" id="owl">
<div class="hand"></div>
<div class="hand hand-r"></div>
<div class="arms">
<div class="arm"></div>
<div class="arm arm-r"></div>
</div>
</div>
<div class="input-box">
<input type="text" placeholder="手机号" onblur="regPhone()" id="account"><span id="regPhone"></span>
<input type="password" placeholder="密码" onblur="regPwd()" id="password"><span id="regPwd"></span>
<button id="submit">登录</button>
</div>
</div>
</div>
</body>
</html>
CSS代码
*{
/* 初始化 */
margin: 0;
padding: 0;
}
#regPwd,#regPhone{
margin-top: -15px;
margin-bottom: 10px;
}
body{
/* 100%窗口高度 */
height: 100vh;
/* 弹性布局 居中 */
display: flex;
justify-content: center;
align-items: center;
/* background-image: url(../Images/login_back.jpg); */
background-size: 100%;
/* 渐变背景 */
/* background: linear-gradient(200deg,#72afd3,#96fbc4); */
}
.back {
width: 25%;
height: 400px;
padding: 20px;
margin-left: 500px;
margin-top: 20px;
padding-top: 140px;
border-radius: 10px;
background-color: #ffffffdb
}
.login-box{
/* 相对定位 */
position: relative;
width: 320px;
}
.input-box{
/* 弹性布局 垂直排列 */
display: flex;
flex-direction: column;
}
.input-box input {
height: 40px;
border-radius: 3px;
text-indent: 15px;
outline: none;
margin-top: -2px;
border: none;
border: 1px solid #20b2aa;
margin-bottom: 25px;
}
.input-box input:focus{
outline: 1px solid lightseagreen;
}
.input-box button{
border: none;
height: 45px;
background-color: lightseagreen;
color: #fff;
border-radius: 3px;
cursor: pointer;
}
/* 接下来是猫头鹰的样式 */
.owl{
width: 211px;
height: 108px;
/* 背景图片 */
background: url("../Images/face1.png") no-repeat;
/* 绝对定位 */
position: absolute;
top: -100px;
/* 水平居中 */
left: 50%;
transform: translateX(-50%);
}
.owl .hand{
width: 34px;
height: 34px;
border-radius: 40px;
background-color: #ace4ff;
/* 绝对定位 */
position: absolute;
left: 12px;
bottom: -8px;
/* 沿Y轴缩放0.6倍(压扁) */
transform: scaleY(0.6);
/* 动画过渡 */
transition: 0.3s ease-out;
}
.owl .hand.hand-r{
left: 170px;
}
.owl.password .hand{
transform: translateX(42px) translateY(-15px) scale(0.7);
}
.owl.password .hand.hand-r{
transform: translateX(-42px) translateY(-15px) scale(0.7);
}
.owl .arms{
position: absolute;
top: 58px;
width: 100%;
height: 41px;
overflow: hidden;
}
.owl .arms .arm{
width: 40px;
height: 65px;
position: absolute;
left: 20px;
top: 40px;
background: url("../Images/arm1.png") no-repeat;
transform: rotate(-20deg);
transition: 0.3s ease-out;
}
.owl .arms .arm.arm-r{
transform: rotate(20deg) scaleX(-1);
left: 158px;
}
.owl.password .arms .arm{
transform: translateY(-40px) translateX(40px);
}
.owl.password .arms .arm.arm-r{
transform: translateY(-40px) translateX(-40px) scaleX(-1);
}