制作3D半拟态(Neumorphism)风格的登录页面。包含: - 半拟态设计风格 - 流体动画背景 - 完整登录表单 - 微交互动效 - 粒子背景效果 - 适配暗色/亮色主题…
- User
制作3D半拟态(Neumorphism)风格的登录页面。包含: - 半拟态设计风格 - 流体动画背景 - 完整登录表单 - 微交互动效 - 粒子背景效果 - 适配暗色/亮色主题 使用现代CSS技术实现。
Assistant
制作3D半拟态(Neumorphism)风格的登录页面。包含: - 半拟态设计风格 - 流体动画背景 - 完整登录表单 - 微交互动效 - 粒子背景效果 - 适配暗色/亮色主题 使用现代CSS技术实现。
下面是一个完整的3D半拟态风格登录页面实现,包含所有您要求的元素。这个设计使用了现代CSS技术,包括CSS变量、3D变换、过渡动画和粒子效果。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D半拟态登录页面</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
<div class="theme-toggle">
<i class="fas fa-moon"></i>
<i class="fas fa-sun"></i>
</div>
<div class="particles" id="particles"></div>
<div class="container">
<div class="login-card">
<div class="card-header">
<h1>欢迎登录</h1>
<p>请输入您的凭据</p>
</div>
<form class="login-form">
<div class="input-group">
<label for="username">用户名</label>
<div class="input-container">
<input type="text" id="username" placeholder="输入用户名" required>
<i class="fas fa-user"></i>
</div>
</div>
<div class="input-group">
<label for="password">密码</label>
<div class="input-container">
<input type="password" id="password" placeholder="输入密码" required>
<i class="fas fa-lock"></i>
<i class="fas fa-eye-slash toggle-password"></i>
</div>
</div>
<div class="options">
<div class="remember-me">
<input type="checkbox" id="remember">
<label for="remember">记住我</label>
</div>
<a href="#" class="forgot-password">忘记密码?</a>
</div>
<button type="submit" class="login-button">
<span>登录</span>
<div class="button-shadow"></div>
</button>
<div class="social-login">
<p>或使用其他方式登录</p>
<div class="social-icons">
<div class="icon google">
<i class="fab fa-google"></i>
</div>
<div class="icon facebook">
<i class="fab fa-facebook-f"></i>
</div>
<div class="icon twitter">
<i class="fab fa-twitter"></i>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="fluid-background"></div>
</body>
</html>
:root {
--primary-color: #6c5ce7;
--secondary-color: #a29bfe;
--text-color: #2d3436;
--text-secondary: #636e72;
--bg-color: #f5f6fa;
--card-bg: #f5f6fa;
--shadow-color: rgba(108, 92, 231, 0.1);
--shadow-inset: rgba(255, 255, 255, 0.7);
--neumorphic-shadow: 8px 8px 15px var(--shadow-color),
-8px -8px 15px var(--shadow-inset);
--neumorphic-inset: inset 2px 2px 5px var(--shadow-color),
inset -2px -2px 5px var(--shadow-inset);
--transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
[data-theme="dark"] {
--primary-color: #6c5ce7;
--secondary-color: #a29bfe;
--text-color: #f5f6fa;
--text-secondary: #b2bec3;
--bg-color: #2d3436;
--card-bg: #2d3436;
--shadow-color: rgba(0, 0, 0, 0.3);
--shadow-inset: rgba(45, 52, 54, 0.7);
--neumorphic-shadow: 8px 8px 15px var(--shadow-color),
-8px -8px 15px var(--shadow-inset);
--neumorphic-inset: inset 2px 2px 5px var(--shadow-color),
inset -2px -2px 5px var(--shadow-inset);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
transition: var(--transition);
}
.theme-toggle {
position: absolute;
top: 20px;
right: 20px;
width: 60px;
height: 30px;
background-color: var(--card-bg);
border-radius: 30px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 5px;
cursor: pointer;
box-shadow: var(--neumorphic-shadow);
z-index: 100;
transition: var(--transition);
}
.theme-toggle i {
font-size: 18px;
color: var(--text-color);
transition: var(--transition);
}
.theme-toggle i:first-child {
opacity: 1;
}
.theme-toggle i:last-child {
opacity: 0;
}
[data-theme="dark"] .theme-toggle i:first-child {
opacity: 0;
}
[data-theme="dark"] .theme-toggle i:last-child {
opacity: 1;
}
.container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
perspective: 1000px;
z-index: 1;
}
.login-card {
width: 100%;
max-width: 450px;
background-color: var(--card-bg);
border-radius: 20px;
padding: 40px;
box-shadow: var(--neumorphic-shadow);
position: relative;
transform-style: preserve-3d;
transition: var(--transition);
z-index: 2;
}
.login-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 20px;
background: linear-gradient(145deg,
rgba(255, 255, 255, 0.1) 0%,
rgba(0, 0, 0, 0.05) 100%);
opacity: 0.5;
z-index: -1;
}
.card-header {
text-align: center;
margin-bottom: 30px;
}
.card-header h1 {
font-size: 28px;
font-weight: 700;
margin-bottom: 10px;
color: var(--primary-color);
}
.card-header p {
font-size: 14px;
color: var(--text-secondary);
}
.login-form {
display: flex;
flex-direction: column;
gap: 20px;
}
.input-group {
display: flex;
flex-direction: column;
gap: 8px;
}
.input-group label {
font-size: 14px;
font-weight: 500;
color: var(--text-secondary);
}
.input-container {
position: relative;
}
.input-container input {
width: 100%;
padding: 15px 20px 15px 45px;
border: none;
border-radius: 10px;
background-color: var(--card-bg);
font-size: 16px;
color: var(--text-color);
box-shadow: var(--neumorphic-inset);
transition: var(--transition);
}
.input-container input:focus {
outline: none;
box-shadow: 0 0 0 2px var(--primary-color),
var(--neumorphic-inset);
}
.input-container i {
position: absolute;
left: 15px;
top: 50%;
transform: translateY(-50%);
color: var(--text-secondary);
transition: var(--transition);
}
.input-container input:focus + i {
color: var(--primary-color);
}
.toggle-password {
left: auto;
right: 15px;
cursor: pointer;
}
.options {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 14px;
}
.remember-me {
display: flex;
align-items: center;
gap: 5px;
}
.remember-me input {
width: 16px;
height: 16px;
accent-color: var(--primary-color);
}
.forgot-password {
color: var(--primary-color);
text-decoration: none;
transition: var(--transition);
}
.forgot-password:hover {
text-decoration: underline;
}
.login-button {
position: relative;
width: 100%;
padding: 15px;
border: none;
border-radius: 10px;
background-color: var(--primary-color);
color: white;
font-size: 16px;
font-weight: 600;
cursor: pointer;
overflow: hidden;
box-shadow: var(--neumorphic-shadow);
transition: var(--transition);
transform: translateZ(0);
z-index: 1;
}
.login-button:hover {
transform: translateY(-3px) translateZ(0);
box-shadow: 10px 10px 20px var(--shadow-color),
-10px -10px 20px var(--shadow-inset);
}
.login-button:active {
transform: translateY(1px) translateZ(0);
}
.login-button span {
position: relative;
z-index: 2;
}
.button-shadow {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 10px;
z-index: 0;
transition: var(--transition);
}
.login-button:hover .button-shadow {
background-color: rgba(0, 0, 0, 0.15);
}
.social-login {
margin-top: 20px;
text-align: center;
}
.social-login p {
font-size: 14px;
color: var(--text-secondary);
margin-bottom: 15px;
position: relative;
}
.social-login p::before,
.social-login p::after {
content: '';
position: absolute;
top: 50%;
width: 30%;
height: 1px;
background-color: var(--text-secondary);
opacity: 0.3;
}
.social-login p::before {
left: 0;
}
.social-login p::after {
right: 0;
}
.social-icons {
display: flex;
justify-content: center;
gap: 20px;
}
.icon {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
box-shadow: var(--neumorphic-shadow);
transition: var(--transition);
}
.icon:hover {
transform: translateY(-3px);
}
.icon i {
font-size: 18px;
color: var(--text-color);
}
.google {
background-color: #db4437;
}
.google i {
color: white;
}
.facebook {
background-color: #4267B2;
}
.facebook i {
color: white;
}
.twitter {
background-color: #1DA1F2;
}
.twitter i {
color: white;
}
/* 流体背景效果 */
.fluid-background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(45deg, rgba(108, 92, 231, 0.1), rgba(162, 155, 254, 0.1));
z-index: 0;
opacity: 0.5;
animation: fluid 15s ease-in-out infinite;
pointer-events: none;
}
@keyframes fluid {
0%, 100% {
border-radius: 60% 40% 30% 70%/60% 30% 70% 40%;
}
25% {
border-radius: 30% 60% 70% 40%/50% 60% 30% 60%;
}
50% {
border-radius: 50% 50% 30% 70%/50% 50% 70% 50%;
}
75% {
border-radius: 70% 30% 50% 50%/30% 70% 50% 50%;
}
}
/* 粒子效果 */
.particles {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
pointer-events: none;
}
.particle {
position: absolute;
background-color: var(--primary-color);
border-radius: 50%;
opacity: 0.5;
animation: float 15s linear infinite;
}
@keyframes float {
0% {
transform: translateY(0) rotate(0deg);
}
100% {
transform: translateY(-1000px) rotate(720deg);
}
}
/* 响应式设计 */
@media (max-width: 768px) {
.login-card {
padding: 30px 20px;
}
.card-header h1 {
font-size: 24px;
}
}
document.addEventListener('DOMContentLoaded', function() {
// 主题切换
const themeToggle = document.querySelector('.theme-toggle');
const body = document.body;
themeToggle.addEventListener('click', function() {
const currentTheme = body.getAttribute('data-theme');
if (currentTheme === 'dark') {
body.removeAttribute('data-theme');
localStorage.setItem('theme', 'light');
} else {
body.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
}
});
// 检查本地存储中的主题偏好
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
body.setAttribute('data-theme', 'dark');
}
// 密码可见性切换
const togglePassword = document.querySelector('.toggle-password');
const passwordInput = document.getElementById('password');
togglePassword.addEventListener('click', function() {
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
passwordInput.setAttribute('type', type);
this.classList.toggle('fa-eye');
this.classList.toggle('fa-eye-slash');
});
// 创建粒子效果
const particlesContainer = document.getElementById('particles');
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
createParticle();
}
function createParticle() {
const particle = document.createElement('div');
particle.classList.add('particle');
// 随机大小
const size = Math.random() * 5 + 2;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// 随机位置
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100 + 100}%`;
// 随机动画持续时间
const duration = Math.random() * 10 + 10;
particle.style.animationDuration = `${duration}s`;
// 随机延迟
particle.style.animationDelay = `${Math.random() * 5}s`;
// 随机透明度
particle.style.opacity = Math.random() * 0.5 + 0.1;
particlesContainer.appendChild(particle);
}
// 表单提交动画
const loginForm = document.querySelector('.login-form');
const loginButton = document.querySelector('.login-button');
loginForm.addEventListener('submit', function(e) {
e.preventDefault();
// 模拟登录动画
loginButton.classList.add('loading');
setTimeout(() => {
loginButton.classList.remove('loading');
alert('登录成功!(这是一个演示)');
}, 2000);
});
// 添加按钮加载动画
const style = document.createElement('style');
style.textContent = `
.login-button.loading {
position: relative;
}
.login-button.loading span {
visibility: hidden;
opacity: 0;
}
.login-button.loading::after {
content: '';
position: absolute;
width: 20px;
height: 20px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border: 3px solid transparent;
border-top-color: white;
border-radius: 50%;
animation: buttonLoading 1s ease infinite;
}
@keyframes buttonLoading {
from { transform: rotate(0turn); }
to { transform: rotate(1turn); }
}
`;
document.head.appendChild(style);
// 输入框微交互
const inputs = document.querySelectorAll('.input-container input');
inputs.forEach(input => {
input.addEventListener('focus', function() {
this.parentElement.style.boxShadow = '0 0 0 2px var(--primary-color), var(--neumorphic-inset)';
});
input.addEventListener('blur', function() {
this.parentElement.style.boxShadow = 'var(--neumorphic-inset)';
});
});
// 卡片悬停效果
const loginCard = document.querySelector('.login-card');
loginCard.addEventListener('mousemove', function(e) {
const xAxis = (window.innerWidth / 2 - e.pageX) / 25;
const yAxis = (window.innerHeight / 2 - e.pageY) / 25;
this.style.transform = `rotateY(${xAxis}deg) rotateX(${yAxis}deg)`;
});
loginCard.addEventListener('mouseenter', function() {
this.style.transition = 'none';
});
loginCard.addEventListener('mouseleave', function() {
this.style.transform = 'rotateY(0deg) rotateX(0deg)';
this.style.transition = 'transform 0.5s ease';
});
});
半拟态设计风格:
流体动画背景:
完整登录表单:
微交互动效:
粒子背景效果:
暗色/亮色主题:
这个设计完全使用现代CSS技术实现,包括CSS变量、3D变换、过渡动画和自定义属性。JavaScript主要用于交互功能和动态效果。