首页 > 其他分享 >CSS、JS之密码灯登录表单

CSS、JS之密码灯登录表单

时间:2024-08-30 14:55:16浏览次数:5  
标签:body JS show color 表单 设置 password CSS 255

效果演示

实现了一个登录页面,包括一个标题、两个输入框(用户名和密码)、一个登录按钮和一个眼睛图标。点击眼睛图标可以显示或隐藏密码。页面背景有两个圆形的半透明元素,整个页面使用了flex布局,并且在水平和垂直方向上都居中对齐。登录框使用了阴影效果和圆角边框,并且在水平和垂直方向上都居中对齐。输入框和登录按钮都使用了圆角边框,并且在水平方向上居中对齐。在输入框中输入密码时,可以点击眼睛图标来显示或隐藏密码。同时,当点击眼睛图标时,页面背景会变成黑色,登录框的样式也会有所变化。

Code

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密码灯登录表单</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <link rel="stylesheet" href="./16-密码灯登录表单.css">
</head>

<body>
    <div class="container">
        <h1>登录</h1>
        <div class="ipt-box">
            <input type="text" placeholder="账号" autocomplete="off">
        </div>
        <div class="ipt-box">
            <input type="password" id="password" placeholder="密码" autocomplete="off">
            <i class="eye fa fa-eye-slash"></i>
            <div class="beam"></div>
        </div>
        <button class="btn-login">登录</button>
    </div>
</body>

</html>
<script src="./16-密码灯登录表单.js"></script>
CSS
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fefefe;
    overflow: hidden;
}

body::before,
body::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    z-index: 0;
}

body::before {
    width: 30vh;
    height: 30vh;
    background-color: #7875ac40;
    top: 10vh;
    left: -10vh;
}

body::after {
    width: 60vh;
    height: 60vh;
    background-color: #7875ac20;
    bottom: -15vh;
    right: -15vh;
}

.container {
    position: relative;
    z-index: 1;
    width: 500px;
    height: 450px;
    background-color: #fff;
    box-shadow: 0 8px 50px rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

h1 {
    font-size: 40px;
    width: 75%;
    letter-spacing: 10px;
    margin-bottom: 30px;
}

.ipt-box {
    width: 75%;
    margin: 10px 0;
    border-radius: 5px;
    position: relative;
    z-index: 2;
}

.ipt-box input {
    width: 100%;
    font-size: 16px;
    padding: 15px;
    border: 1px solid #e3e3e3;
    border-radius: 5px;
    outline: none;
    background: none;
    position: relative;
    z-index: 2;
}

.ipt-box input[type="password"]::-ms-reveal,
.ipt-box input[type="password"]::-ms-clear {
    display: none;
}

.ipt-box .eye {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    z-index: 3;
    cursor: pointer;
}

.btn-login {
    width: 75%;
    height: 50px;
    margin-top: 30px;
    border: none;
    outline: none;
    background-color: #7875ac;
    color: #fff;
    border-radius: 5px;
    font-size: 18px;
    letter-spacing: 8px;
    text-indent: 8px;
    cursor: pointer;
}

.beam {
    width: 100vw;
    height: 25vw;
    position: absolute;
    z-index: 1;
    top: 50%;
    right: 30px;
    clip-path: polygon(100% 50%, 100% 50%, 0 0, 0 100%);
    transform: translateY(-50%) rotate(var(--beam-deg, 0));
    transform-origin: 100% 50%;
    transition: transform 0.2s ease-out;
}

body.show-password {
    background-color: #000;
}

body.show-password::before,
body.show-password::after {
    display: none;
}

.show-password .container {
    background-color: rgba(255, 255, 255, 0.05);
    box-shadow: 0 8px 50px rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.show-password h1 {
    color: #fff;
}

.show-password .ipt-box {
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.show-password input {
    color: #fff;
    border: 1px solid #000;
}

.show-password #password {
    color: #000;
}

.show-password .beam {
    background-color: yellow;
}

.show-password .btn-login {
    background-color: #fff;
    color: #000;
}

.show-password .eye {
    color: #fff;
}
JavaScript
const body=document.body;
const eye=document.querySelector('.eye');
const beam=document.querySelector('.beam');
const passwordInput=document.getElementById('password');

body.addEventListener('mousemove',function(e){
    let rect=beam.getBoundingClientRect();
    let mouseX=rect.right+(rect.width/2);
    let mouseY=rect.top+(rect.height/2);
    let rad=Math.atan2(mouseX-e.pageX,mouseY-e.pageY);
    let deg=(rad*(20/Math.PI)*-1)-350;
    body.style.setProperty('--beam-deg',deg+'deg');
})

eye.addEventListener('click',function(e){
    e.preventDefault();
    body.classList.toggle('show-password');
    passwordInput.type=passwordInput.type==='password'?'text':'password';
    eye.className='eye fa '+(passwordInput.type==='password'?'fa-eye-slash':'fa-eye');
    passwordInput.focus();
})

实现思路拆分

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

这段代码是将所有元素的外边距和内边距都设置为0,并将盒模型设置为border-box,以便更好地控制页面布局。

body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fefefe;
  overflow: hidden;
}

这段代码设置了body元素的高度为100vh,使其占据整个视口的高度。同时,将其设置为flex布局,并将其子元素在水平和垂直方向上都居中对齐。背景颜色设置为#fefefe,overflow属性设置为hidden,以便隐藏页面滚动条。

body::before,
body::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  z-index: 0;
}

body::before {
  width: 30vh;
  height: 30vh;
  background-color: #7875ac40;
  top: 10vh;
  left: -10vh;
}

body::after {
  width: 60vh;
  height: 60vh;
  background-color: #7875ac20;
  bottom: -15vh;
  right: -15vh;
}

这段代码设置了两个伪元素,用于创建页面背景的两个圆形半透明元素。使用了绝对定位,并将其border-radius属性设置为50%,以便将其设置为圆形。z-index属性设置为0,以便将其放在页面底部。before伪元素的宽度和高度分别为30vh,背景颜色为#7875ac40,top和left属性分别为10vh和-10vh。after伪元素的宽度和高度分别为60vh,背景颜色为#7875ac20,bottom和right属性分别为-15vh和-15vh。

.container {
  position: relative;
  z-index: 1;
  width: 500px;
  height: 450px;
  background-color: #fff;
  box-shadow: 0 8px 50px rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

这段代码设置了一个名为.container的元素,用于包含登录框的所有内容。使用了相对定位,并将其z-index属性设置为1,以便将其放在页面顶部。宽度和高度分别为500px和450px,背景颜色为#fff,添加了一个阴影效果,边框半径设置为10px。使用了flex布局,并将其子元素在垂直方向上居中对齐。

h1 {
  font-size: 40px;
  width: 75%;
  letter-spacing: 10px;
  margin-bottom: 30px;
}

这段代码设置了一个标题元素,使用了40px的字体大小,宽度为75%,字母间距为10px,下边距为30px。

.ipt-box {
  width: 75%;
  margin: 10px 0;
  border-radius: 5px;
  position: relative;
  z-index: 2;
}

.ipt-box input {
  width: 100%;
  font-size: 16px;
  padding: 15px;
  border: 1px solid #e3e3e3;
  border-radius: 5px;
  outline: none;
  background: none;
  position: relative;
  z-index: 2;
}

.ipt-box input[type="password"]::-ms-reveal,
.ipt-box input[type="password"]::-ms-clear {
  display: none;
}

.ipt-box .eye {
  position: absolute;
  top: 50%;
  right: 15px;
  transform: translateY(-50%);
  z-index: 3;
  cursor: pointer;
}

这段代码设置了两个输入框和一个眼睛图标。.ipt-box元素用于包含输入框,宽度为75%,上下边距为10px,边框半径为5px,使用了相对定位,并将其z-index属性设置为2,以便将其放在标题元素之上。输入框的宽度为100%,字体大小为16px,内边距为15px,边框为1px的实线,边框半径为5px,outline属性设置为none,以便去除默认的外边框。同时,将其背景设置为none,以便更好地控制样式。input[type="password"]::-ms-reveal和input[type="password"]::-ms-clear属性设置为display:none,以便隐藏IE浏览器中的密码可见性按钮。.eye元素用于显示眼睛图标,使用了绝对定位,并将其top和right属性分别设置为50%和15px,以便将其放在输入框的右侧。使用了translateY(-50%)将其垂直居中对齐,z-index属性设置为3,以便将其放在输入框之上。同时,将其光标设置为指针。

.btn-login {
  width: 75%;
  height: 50px;
  margin-top: 30px;
  border: none;
  outline: none;
  background-color: #7875ac;
  color: #fff;
  border-radius: 5px;
  font-size: 18px;
  letter-spacing: 8px;
  text-indent: 8px;
  cursor: pointer;
}

这段代码设置了一个登录按钮,宽度为75%,高度为50px,上边距为30px,边框为none,outline属性设置为none,背景颜色为#7875ac,字体颜色为#fff,边框半径为5px,字体大小为18px,字母间距为8px,首行缩进为8px,光标设置为指针。

.beam {
  width: 100vw;
  height: 25vw;
  position: absolute;
  z-index: 1;
  top: 50%;
  right: 30px;
  clip-path: polygon(100% 50%, 100% 50%, 0 0, 0 100%);
  transform: translateY(-50%) rotate(var(--beam-deg, 0));
  transform-origin: 100% 50%;
  transition: transform 0.2s ease-out;
}

这段代码设置了一个名为beam的元素,用于显示一个黄色的光束。使用了绝对定位,并将其z-index属性设置为1,以便将其放在页面顶部。宽度为100vw,高度为25vw,top和right属性分别为50%和30px,以便将其放在页面右侧中央。clip-path属性设置为polygon(100% 50%, 100% 50%, 0 0, 0 100%),以便将其设置为一个三角形。transform属性设置为translateY(-50%)和rotate(var(--beam-deg, 0)),以便将其垂直居中对齐并旋转指定角度。transform-origin属性设置为100% 50%,以便将其旋转中心设置为右侧中央。transition属性设置为transform 0.2s ease-out,以便添加一个过渡效果。

body.show-password {
  background-color: #000;
}

body.show-password::before,
body.show-password::after {
  display: none;
}

.show-password .container {
  background-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 8px 50px rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.show-password h1 {
  color: #fff;
}

.show-password .ipt-box {
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.show-password input {
  color: #fff;
  border: 1px solid #000;
}

.show-password #password {
  color: #000;
}

.show-password .beam {
  background-color: yellow;
}

.show-password .btn-login {
  background-color: #fff;
  color: #000;
}

.show-password .eye {
  color: #fff;
}

这段代码设置了当点击眼睛图标时,页面背景、登录框、输入框、标题、登录按钮和光束的样式都会有所变化。body.show-password设置为黑色背景。同时,将body::before和body::after伪元素的display属性设置为none,以便隐藏页面背景的两个圆形半透明元素。.container元素的背景颜色设置为rgba(255, 255, 255, 0.05),添加了一个半透明的背景色。同时,添加了一个阴影效果和一个边框。h1元素的字体颜色设置为#fff。.ipt-box元素的边框颜色设置为rgba(255, 255, 255, 0.5)。输入框的字体颜色设置为#fff,边框颜色设置为#000。#password元素的字体颜色设置为#000。.beam元素的背景颜色设置为yellow。.btn-login元素的背景颜色设置为#fff,字体颜色设置为#000。.eye元素的字体颜色设置为#fff。

标签:body,JS,show,color,表单,设置,password,CSS,255
From: https://blog.csdn.net/zhangliwen1101/article/details/141718118

相关文章

  • CSS、JS之滚动导航栏
    效果演示实现了一个滚动导航栏,包括一个固定在页面顶部的导航栏和四个全屏高度的区块。导航栏的背景颜色为半透明黑色,高度为60px,导航链接为白色,字体大小为30px,链接之间有15px的间距。当鼠标悬停在链接上时,下划线会出现。四个区块的背景颜色分别为#95e1d3、#eaffd0、#fce38a......
  • 基于surging 如何利用peerjs进行语音视频通话
    一、概述PeerJS是一个基于浏览器WebRTC功能实现的js功能包,简化了WebrRTC的开发过程,对底层的细节做了封装,直接调用API即可,再配合surging协议组件化从而做到稳定,高效可扩展的微服务,再利用RtmpToWebrtc引擎组件可以做到不仅可以利用httpflv观看rtmp推流直播,还可以采用基于W......
  • uniapp js 划消小游戏 1.0 去控制台看打印(仅作参考)
    <template> <viewclass="wrap">  划消:{{sdNum}}*{{sdNum}}  <viewclass="btn"style="padding:32rpx;background:pink"@click="clickBtn">点击划消按钮</view>  <viewclass="btn&q......
  • uniapp js 数独小游戏 写死的简单数独 数独 3.0
    <template> <viewclass="wrap">  数独:{{sdNum}}*{{sdNum}}  <viewclass="btn"style="padding:32rpx;background:pink"@click="startFun">点击开始计时</view>  <viewclass="btn&q......
  • 基于nodejs_vue+express框架个人健康管理系统的设计与实现_7999g
    个人健康管理系统按照功能由三部分构成的,三部份是用户、医生和管理员。主要功能有出诊医生、预约挂号、健康档案、疾病评枯等。系统软件用户、医生与管理员的功能模块图个人健康服务平台是以医院的状况为起点,综合网络空间开发设计要求。目的是将个人健康通过网络平台变换为在......
  • day15JS-es6的基础语法
     1.严格模式1.1严格模式的使用方法使用方法1:"usestrict";开启严格模式。使用方法2:<scripttype="moaule"></script> 当设置script标签为模块化时,自动启用严格模式。 1.2严格模式的限制1. 要求变量不能重名。//报错"usestrict";vara=2;vara=4; 2.......
  • 分享:JS事件循环机制,宏任务和微任务
     为什么会讲这个主题? 这要从一个bug讲起,10月26号,app端,我的考勤日历面板上的信息在ios上显示不全。效果见手机视频。 当时我们几个排查了2-3天都没找到原因,review代码各种改都不行。(此时打开代码看下,src/app/myAttendance/attendance.vueline298line246)最后通过setTimeo......
  • 技术分享:jsx语法和应用
    首先问问大家对JSX了解多少,可以提几个问题,引发大家的思考和求知欲。然后开始讲 JSX是React架构里的东西,但是不局限于React,它是一种JavaScript的语法扩展,完全是JavaScript内部实现的,所以vue里面也能用。 JSX的优点:JSX执行更快,因为它在编译为JavaScript代码后进行了优化它是......
  • JS动态引入模块
    这是静态引入,importxxfrom‘xxx’;这是动态引入,import('xxx')动态引入是一个异步操作,即它会返回一个Promise对象,因此我们可以捕获引入失败的异常。具体运用场景:路由由后端动态生成,前端根据获取到的路由动态生成菜单,并根据对应路由去找到对应的组件进行跳转。譬如路由为/hom......
  • 基于ssm+vue.js的山东红色旅游信息管理系统附带文章源码部署视频讲解等
    文章目录前言详细视频演示具体实现截图核心技术介绍后端框架SSM前端框架Vue持久层框架MyBaits为什么选择我代码参考数据库参考测试用例参考源码获取前言......