JS实现漂亮的登录页面(氛围感页面)

代码:

javascript 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        body{
            background-color: #ece9f0;
        }
        .box{
            width: 800px;
            height: 300px;
            margin: 0 auto;
            margin-top: 20px;
            box-shadow: 0px 0px 20px black;
            background-color: #c8e0c8;
            padding-top: 30px;
            text-align: center;
            font-size: 18px;
        }
  
       label{
            display: inline-block;
            width: 80px;
       }
       .msg{
            margin-top: 20px;
       }
       input{
            height: 20px;
            border: 0;
       }
       input::placeholder{
            color: #f7c7d9;
       }
       .zc{
            font-size: 30px;
            font-weight: bold;
       }
       .djzc{
            color: skyblue;
            border: 0;
            font-weight: bold;
            width: 80px;
            height: 30px;
       }
    </style> 
</head>
<body>
    <div class="box">
       <div class="zc">登录页</div>
       <div class="msg">
            <label class="yhm">用户名:</label><input type="text" placeholder="请输入用户名">
       </div>
       
       <div class="msg">
            <label class="pwd">密码:</label><input type="password" placeholder="请输入密码">
       </div>
       
       <div class="msg">
            <button class="djzc" onclick="registerfun()">点击登录</button>
       </div>
       
    </div>
    <script src="https://api.vvhan.com/api/script/snow"></script>
    <script src="https://api.vvhan.com/api/script/bolang"></script>
    <script src="https://api.vvhan.com/api/script/yinghua"></script>
    <script src="https://api.vvhan.com/api/script/yinghua"></script>
    <script src="https://api.vvhan.com/api/script/denglong"></script>
    <script>
        let box = document.querySelector('.box')
        let zc = document.querySelector('.zc')
        let yhm = document.querySelector('.yhm')
        let pwd = document.querySelector('.pwd')


        setInterval(()=>{
            box.style.boxShadow=`0px 0px 20px rgb(${sj()},${sj()},${sj()})`
            zc.style.color=`rgb(${sj()},${sj()},${sj()})`
            yhm.style.color=`rgb(${sj()},${sj()},${sj()})`
            pwd.style.color=`rgb(${sj()},${sj()},${sj()})`
            zc.style.textShadow=` 0px 0px 10px rgb(${sj()},${sj()},${sj()})`
        },1000)
        function sj(){
            return Math.floor(Math.random()*255)
        }
         // 点击之后的注册方法
         function registerfun(params) {
             // 获取输入框的内容
            let user_name = document.querySelectorAll('input')[0].value
            let password = document.querySelectorAll('input')[1].value
            // 准备ajax向后端发送数据
            let xhr = new XMLHttpRequest()
            // 请求方式和请求地址
            xhr.open('post','http://api.poiuy.top/users/login')
            xhr.setRequestHeader('Content-type','application/json')
            xhr.send(JSON.stringify({
                user_name,
                password,
            }))
            xhr.onload= function(params) {
                let data = JSON.parse(xhr.responseText);
                let token = data.result.token
                    console.log(token);
                localStorage.setItem('token',token)
                    // 判断状态码
                    // 如果是0代表成功 跳转到登陆
                if (data.code==0) {
                    alert('登录成功,即将跳转列表页')
                    location.href = 'list.html'
                }else{
                    // 否则提示错误信息
                    alert(data.message)
                }  
            }  
        }
        
       
  
    </script>
</body>
</html>

效果图:

相关推荐
Eshine、31 分钟前
解决前端项目中,浏览器无法正常加载带.gz名称的文件
前端·vue3·.gz·.gz名称的js文件无法被加载
q***38511 小时前
TypeScript 与后端开发Node.js
javascript·typescript·node.js
用户47949283569151 小时前
别再当 AI 的"人肉定位器"了:一个工具让 React 组件秒定位
前端·aigc·ai编程
Nan_Shu_6141 小时前
学习:Sass
javascript·学习·es6
WYiQIU2 小时前
面了一次字节前端岗,我才知道何为“造火箭”的极致!
前端·javascript·vue.js·react.js·面试
qq_316837752 小时前
uniapp 观察列表每个元素的曝光时间
前端·javascript·uni-app
小夏同学呀2 小时前
在 Vue 2 中实现 “点击下载条码 → 打开新窗口预览 → 自动唤起浏览器打印” 的功能
前端·javascript·vue.js
芳草萋萋鹦鹉洲哦2 小时前
【vue】导航栏变动后刷新router的几种方法
前端·javascript·vue.js
zero13_小葵司2 小时前
JavaScript性能优化系列(八)弱网环境体验优化 - 8.3 数据预加载与缓存:提前缓存关键数据
javascript·缓存·性能优化
1***y1782 小时前
Vue项目性能优化案例
前端·vue.js·性能优化