赞
踩
index.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>log_in</title> <script src="script.js"></script> <link rel="stylesheet" href="css/style.css" /> </head> <body> <div class="container"> <h1>Please login</h1> <form> <div class="form-control"> <input type="text" required> <label> Email </label> </div> <div class="form-control"> <input type="password" required> <label>password</label> </div> <button class="btn">Login</button> <p class="text">Don't have an account?<a href="">Register</a></p> </form> </div> </body> </html>
style.css
* { margin: 0; padding: 0; box-sizing: border-box; } body { height: 100vh; background: rgb(255, 94, 249); background: linear-gradient(144deg, rgba(255, 94, 249, 1) 19%, rgba(104, 185, 251, 1) 86%); color: white; font-family: sans-serif; display: flex; justify-content: center; align-items: center; } /* 表单属性 */ .container { background-color: rgb(0, 0, 0, 0.4); padding: 20px 40px; border-radius: 5px; } /* 表单中标题属性 */ .container h1 { text-align: center; margin-bottom: 30px; font-family: '楷体', '微软雅黑'; } /* 鼠标经过时字体颜色改变 */ .container h1:hover { background-image: linear-gradient(90deg, #673ab7, #e91e63); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-image: linear-gradient(90deg, rgb(255, 167, 69), rgb(254, 134, 159), rgb(239, 122, 200), rgb(160, 131, 237), rgb(67, 174, 255), rgb(160, 131, 237), rgb(239, 122, 200), rgb(254, 134, 159), rgb(255, 167, 69)); background-size: 200%; animation: streamer 3s linear infinite; } /* 字体颜色变化的动画 */ @keyframes streamer { 0% { background-position: 200%; } 100% { background-position: 0%; } } /* 按钮的属性 */ .btn { cursor: pointer; width: 100%; background-color: lightblue; padding: 15px; border: 0; font-size: 16px; font-family: inherit; } /* 点击按钮时的属性 */ .btn:focus { outline: 0; } /* 点击按钮时的效果,缩小0.98 */ .btn:active { transform: scale(0.98); } /* 下面注册旁的连接 */ .container a { text-decoration: none; color: lightblue; } .text { margin-top: 30px; } /* 输入框所在容器的类 */ .form-control { width: 300px; margin: 20px 0 40px; position: relative; } .form-control input { width: 100%; background-color: transparent; border: 0; border-bottom: 2px solid white; display: block; padding: 15px 0; font-size: 18px; color: white; } /* 获取焦点时下边框变为蓝色 */ .form-control input:focus { outline: 0; border-bottom-color: lightblue; } /*当输入框中有文字时,下边框还是蓝色 valid:检测input有没有填*/ .form-control input:valid { border-bottom-color: lightblue; } /* Email与password的属性 */ .form-control label { position: absolute; left: 0; top: 15px; } /* Email与password的动画效果 */ .form-control label span { display: inline-block; font-size: 18px; transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55); } /* +选择器:选择除了自己之外的其它兄弟元素 */ .form-control input:focus+label span, .form-control input:valid+label span { transform: translateY(-30px); color: lightblue; }
script.js
window.onload = function () {
const labels = document.querySelectorAll(".form-control label")
labels.forEach(label => {
label.innerHTML = label.innerText.split('').map((letter, index) => `<span style="transition-delay:${index * 35}ms">${letter}</span>`).join('');
});
};
完
Login/index.vue
<template> <div class="container"> <h1>Please login</h1> <form @submit.prevent="login"> <div class="form-control"> <input type="text" v-model="email" required> <label> <span v-for="(letter, index) in splitLetters('Email')" :key="index" :style="{transitionDelay: letter.delay}"> {{ letter.char }} </span> </label> </div> <div class="form-control"> <input type="password" v-model="password" required> <label> <span v-for="(letter, index) in splitLetters('Password')" :key="index" :style="{transitionDelay: letter.delay}"> {{ letter.char }} </span> </label> </div> <button class="btn">Login</button> <p class="text">Don't have an account?<a href="#">Register</a></p> </form> </div> </template> <script setup> import {ref} from 'vue'; const email = ref(''); const password = ref(''); const splitLetters = (word) => { return [...word].map((char, index) => ({ char, delay: `${index * 35}ms`, })); }; const login = () => { console.log(email.value, password.value); // 这里处理登录逻辑 }; </script> <style scoped> * { margin: 0; padding: 0; box-sizing: border-box; } .container { min-height: 100vh; /* 视口高度 */ display: flex; flex-direction: column; justify-content: center; /* 垂直居中 */ align-items: center; /* 水平居中 */ background: linear-gradient(144deg, rgba(255, 94, 249, 1) 19%, rgba(104, 185, 251, 1) 86%); /* 背景渐变 */ color: white; /* 文字颜色 */ } /* 表单中标题属性 */ .container h1 { text-align: center; margin-bottom: 30px; font-family: '楷体', '微软雅黑'; } /* 鼠标经过时字体颜色改变 */ .container h1:hover { background-image: linear-gradient(90deg, #673ab7, #e91e63); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-image: linear-gradient(90deg, rgb(255, 167, 69), rgb(254, 134, 159), rgb(239, 122, 200), rgb(160, 131, 237), rgb(67, 174, 255), rgb(160, 131, 237), rgb(239, 122, 200), rgb(254, 134, 159), rgb(255, 167, 69)); background-size: 200%; animation: streamer 3s linear infinite; } /* 字体颜色变化的动画 */ @keyframes streamer { 0% { background-position: 200%; } 100% { background-position: 0%; } } /* 按钮的属性 */ .btn { cursor: pointer; width: 100%; background-color: lightblue; padding: 15px; border: 0; font-size: 16px; font-family: inherit; } /* 点击按钮时的属性 */ .btn:focus { outline: 0; } /* 点击按钮时的效果,缩小0.98 */ .btn:active { transform: scale(0.98); } /* 下面注册旁的连接 */ .container a { text-decoration: none; color: lightblue; } .text { margin-top: 30px; } /* 输入框所在容器的类 */ .form-control { width: 300px; margin: 20px 0 40px; position: relative; } .form-control input { width: 100%; background-color: transparent; border: 0; border-bottom: 2px solid white; display: block; padding: 15px 0; font-size: 18px; color: white; } /* 获取焦点时下边框变为蓝色 */ .form-control input:focus { outline: 0; border-bottom-color: lightblue; } /*当输入框中有文字时,下边框还是蓝色 valid:检测input有没有填*/ .form-control input:valid { border-bottom-color: lightblue; } /* Email与password的属性 */ .form-control label { position: absolute; left: 0; top: 15px; } /* Email与password的动画效果 */ .form-control label span { display: inline-block; font-size: 18px; transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55); } /* +选择器:选择除了自己之外的其它兄弟元素 */ .form-control input:focus + label span, .form-control input:valid + label span { transform: translateY(-30px); color: lightblue; } </style>
App.vue
<template> <div id="app"> <Login /> </div> </template> <script> import Login from '@/components/Login/index.vue'; export default { name: 'App', components: { Login:Login }, }; </script> <style> /* Global styles */ html, body, #app { height: 100%; margin: 0; } </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。