效果
完整代码
HTML部分
<div class="login-container" id="loginContainer"> <h2 class="login-title">创新登录系统</h2> <form id="loginForm"> <div class="form-group"> <input type="text" id="username" name="username" placeholder="用户名" required> </div> <div class="form-group"> <input type="password" id="password" name="password" placeholder="密码" required> </div> <button type="submit" class="login-button">登录</button> </form> <div class="forgot-password"> <a href="#">忘记密码?</a> </div> </div>
CSS部分
* { margin: 0; padding: 0; box-sizing: border-box; } body, html { height: 100%; font-family: 'Arial', sans-serif; background: linear-gradient(45deg, #b21f1f, #fdbb2d); background-size: 400% 400%; animation: gradientBG 15s ease infinite; overflow: hidden; } @keyframes gradientBG { 0% {background-position: 0% 50%;} 50% {background-position: 100% 50%;} 100% {background-position: 0% 50%;} } .login-container { background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); border-radius: 20px; padding: 40px; width: 100%; max-width: 400px; margin: 100px auto; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37); border: 1px solid rgba(255, 255, 255, 0.18); transform: perspective(1000px) rotateY(0deg); transition: transform 0.6s ease-out; } .login-container:hover { transform: perspective(1000px) rotateY(-5deg); } .login-title { text-align: center; margin-bottom: 30px; color: #fff; font-size: 28px; text-shadow: 2px 2px 4px rgba(0,0,0,0.5); } .form-group { margin-bottom: 20px; position: relative; } .form-group input { width: 100%; padding: 10px; background: rgba(255, 255, 255, 0.2); border: none; border-radius: 50px; color: #fff; font-size: 16px; transition: all 0.3s ease; } .form-group input::placeholder { color: rgba(255, 255, 255, 0.7); } .form-group input:focus { outline: none; background: rgba(255, 255, 255, 0.3); box-shadow: 0 0 15px rgba(255, 255, 255, 0.5); } .login-button { width: 100%; padding: 12px; background: linear-gradient(45deg, #FF512F, #DD2476); color: #fff; border: none; border-radius: 50px; font-size: 18px; cursor: pointer; transition: all 0.3s ease; position: relative; overflow: hidden; } .login-button:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.3); } .login-button:active { transform: translateY(0); box-shadow: 0 2px 5px rgba(0,0,0,0.3); } .login-button::after { content: ''; position: absolute; top: 50%; left: 50%; width: 5px; height: 5px; background: rgba(255, 255, 255, 0.5); opacity: 0; border-radius: 100%; transform: scale(1, 1) translate(-50%); transform-origin: 50% 50%; } @keyframes ripple { 0% { transform: scale(0, 0); opacity: 1; } 20% { transform: scale(25, 25); opacity: 1; } 100% { transform: scale(50, 50); opacity: 0; } } .login-button:focus:not(:active)::after { animation: ripple 1s ease-out; } .forgot-password { text-align: center; margin-top: 20px; } .forgot-password a { color: #fff; text-decoration: none; font-size: 14px; transition: all 0.3s ease; } .forgot-password a:hover { text-shadow: 0 0 10px rgba(255, 255, 255, 0.8); } @keyframes float { 0% {transform: translateY(0px);} 50% {transform: translateY(-20px);} 100% {transform: translateY(0px);} } .floating-icon { position: absolute; font-size: 40px; opacity: 0.2; pointer-events: none; animation: float 6s ease-in-out infinite; } </style>
Js
function createFloatingIcon(emoji) { const icon = document.createElement('div'); icon.className = 'floating-icon'; icon.style.left = Math.random() * window.innerWidth + 'px'; icon.style.top = Math.random() * window.innerHeight + 'px'; icon.style.animationDelay = Math.random() * 5 + 's'; icon.textContent = emoji; document.body.appendChild(icon); } const emojis = ['🚀', '💻', '📊', '🔐', '📈']; emojis.forEach(createFloatingIcon); document.getElementById('loginForm').addEventListener('submit', function(e) { e.preventDefault(); const button = this.querySelector('.login-button'); button.style.animation = 'none'; button.offsetHeight; // Trigger reflow button.style.animation = null; // 在这里添加登录逻辑 }); document.getElementById('loginContainer').addEventListener('mousemove', function(e) { const { left, top, width, height } = this.getBoundingClientRect(); const x = (e.clientX - left) / width; const y = (e.clientY - top) / height; this.style.transform = ` perspective(1000px) rotateY(${(x - 0.5) * 10}deg) rotateX(${(y - 0.5) * -10}deg) `; }); document.getElementById('loginContainer').addEventListener('mouseleave', function() { this.style.transform = 'perspective(1000px) rotateY(0deg) rotateX(0deg)'; });