博客系统的登录页面详解

登录页面表单 - 详细标签和变量解释

1. 登录页面容器 (Login Page Container)

1
<div id="login-page" style="display: none; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; text-align: center; background: transparent; position: fixed; width: 100%; z-index: 9999;">

标签解释

  • <div> - HTML分区元素,用于创建登录页面的容器

属性解释

  • id="login-page" - 唯一标识符,用于JavaScript获取和操作此元素
  • style="..." - 内联CSS样式

样式属性详解

  • display: none - 初始状态隐藏,只有JavaScript控制显示时才可见
  • flex-direction: column - Flexbox布局,垂直排列子元素
  • align-items: center - 水平居中对齐子元素
  • justify-content: center - 垂直居中对齐子元素
  • min-height: 100vh - 最小高度为视口高度的100%,确保全屏显示
  • text-align: center - 文本居中对齐
  • background: transparent - 背景透明
  • position: fixed - 固定定位,相对于浏览器窗口
  • width: 100% - 宽度占满整个窗口
  • z-index: 9999 - 层级很高,确保在最上层显示

2. 磨砂玻璃背景层 (Frosted Glass Background)

1
<div id="frosted-bg" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); z-index: -1;"></div>

标签解释

  • <div> - 创建磨砂玻璃效果的背景层

属性解释

  • id="frosted-bg" - 磨砂背景的唯一标识符

样式属性详解

  • position: absolute - 绝对定位,相对于最近的定位祖先元素
  • top: 0; left: 0; right: 0; bottom: 0 - 四个方向都设为0,铺满整个父容器
  • background: rgba(255, 255, 255, 0.7) - 半透明白色背景,透明度为0.7
  • backdrop-filter: blur(15px) - 背景模糊效果,15px的模糊半径
  • -webkit-backdrop-filter: blur(15px) - Webkit浏览器的前缀版本
  • z-index: -1 - 负层级,确保在内容层之下

3. 漂浮小球容器 (Bubbles Container)

1
<div id="bubbles-container" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; z-index: -2;"></div>

标签解释

  • <div> - 创建漂浮小球的容器

属性解释

  • id="bubbles-container" - 小球容器的唯一标识符

样式属性详解

  • position: absolute - 绝对定位
  • top: 0; left: 0; right: 0; bottom: 0 - 铺满整个父容器
  • overflow: hidden - 隐藏超出容器的内容
  • z-index: -2 - 比磨砂背景更低的层级

4. 登录表单主体 (Login Form Main)

1
<div style="max-width: 400px; padding: 2.5rem; background: rgba(255, 255, 255, 0.97); border-radius: 16px; box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25); backdrop-filter: blur(15px); transition: all 0.8s cubic-bezier(0.25, 0.8, 0.25, 1);">

标签解释

  • <div> - 登录表单的主要容器

样式属性详解

  • max-width: 400px - 最大宽度400px,确保在移动设备上的可用性
  • padding: 2.5rem - 内边距2.5rem,提供舒适的内部空间
  • background: rgba(255, 255, 255, 0.97) - 几乎不透明的白色背景
  • border-radius: 16px - 圆角边框,16px的圆角半径
  • box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25) - 阴影效果,向下偏移15px,模糊40px,25%透明度
  • backdrop-filter: blur(15px) - 背景模糊效果
  • transition: all 0.8s cubic-bezier(0.25, 0.8, 0.25, 1) - 所有属性的过渡动画,0.8秒,使用贝塞尔曲线缓动函数

5. 锁形图标 (Lock Icon)

1
2
3
4
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="var(--current-theme-color, #8CC8FF)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block; margin: 0 auto;" id="main-lock-icon">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
</svg>

标签解释

  • <svg> - 可缩放矢量图形元素
  • <rect> - 矩形元素,表示锁的主体
  • <path> - 路径元素,表示锁的顶部弧形

属性解释

  • width="64" height="64" - SVG画布尺寸64x64像素
  • viewBox="0 0 24 24" - 视口框,定义SVG的坐标系统
  • fill="none" - 不填充颜色
  • stroke="var(--current-theme-color, #8CC8FF)" - 描边颜色,使用CSS变量,默认值为#8CC8FF
  • stroke-width="2" - 描边宽度2像素
  • stroke-linecap="round" - 线条末端为圆形
  • stroke-linejoin="round" - 线条连接处为圆形
  • id="main-lock-icon" - 主锁图标的唯一标识符

子元素详解

  • <rect x="3" y="11" width="18" height="11" rx="2" ry="2"> - 锁的主体矩形,位置(3,11),尺寸18x11,圆角2x2
  • <path d="M7 11V7a5 5 0 0 1 10 0v4"> - 锁的顶部弧形路径,从(7,11)开始,向上到(7,7),然后画一个5x5的椭圆,最后向下到(7,4)

6. 标题 (Title)

1
<h2 style="margin-bottom: 2rem; color: var(--current-theme-color, #8CC8FF); font-size: 1.75rem; font-weight: 600;" id="main-title">zhyBlogs</h2>

标签解释

  • <h2> - 二级标题元素

属性解释

  • id="main-title" - 主标题的唯一标识符

样式属性详解

  • margin-bottom: 2rem - 下边距2rem
  • color: var(--current-theme-color, #8CC8FF) - 文字颜色,使用CSS变量
  • font-size: 1.75rem - 字体大小1.75rem
  • font-weight: 600 - 字体粗细600(半粗体)

内容

  • zhyBlogs - 博客名称

7. 密码输入区域 (Password Input Area)

1
2
3
4
5
6
7
8
9
<div style="margin-bottom: 1.5rem; position: relative; width: 100%;">
<div style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--current-theme-color, #8CC8FF);" id="password-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
</svg>
</div>
<input type="password" id="pass-input" placeholder="请输入密码" class="login-input" style="width: 100%; padding: 0.85rem 2.5rem; margin-bottom: 0; border: 2px solid transparent; border-radius: 8px; font-size: 16px; transition: all 0.3s ease; background: #f8f9fa; box-sizing: border-box;">
</div>

外层容器

  • <div> - 密码输入区域的容器
  • margin-bottom: 1.5rem - 下边距1.5rem
  • position: relative - 相对定位,为绝对定位的子元素提供参考
  • width: 100% - 宽度占满父容器

密码图标容器

  • <div> - 密码图标的容器
  • id="password-icon" - 密码图标的唯一标识符
  • position: absolute - 绝对定位
  • left: 12px - 距离左边12px
  • top: 50% - 距离顶部50%
  • transform: translateY(-50%) - 向上偏移自身高度的50%,实现垂直居中
  • color: var(--current-theme-color, #8CC8FF) - 图标颜色

密码图标SVG

  • <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> - 18x18像素的锁图标
  • <rect x="3" y="11" width="18" height="11" rx="2" ry="2"> - 锁的主体
  • <path d="M7 11V7a5 5 0 0 1 10 0v4"> - 锁的顶部弧形

密码输入框

  • <input> - 输入框元素
  • type="password" - 密码类型,输入时显示为点
  • id="pass-input" - 密码输入框的唯一标识符
  • placeholder="请输入密码" - 占位符文本
  • class="login-input" - CSS类名
  • style="..." - 内联样式

输入框样式详解

  • width: 100% - 宽度占满父容器
  • padding: 0.85rem 2.5rem - 内边距,上下0.85rem,左右2.5rem
  • margin-bottom: 0 - 下边距为0
  • border: 2px solid transparent - 2px透明边框
  • border-radius: 8px - 8px圆角
  • font-size: 16px - 字体大小16px
  • transition: all 0.3s ease - 所有属性0.3秒缓动过渡
  • background: #f8f9fa - 浅灰色背景
  • box-sizing: border-box - 盒模型,边框和内边距包含在宽度内

8. 验证码输入区域 (Captcha Input Area)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<div style="margin-bottom: 1.5rem; position: relative; width: 100%;">
<div style="display: flex; gap: 12px; align-items: center;">
<div style="flex: 1; position: relative;">
<div style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--current-theme-color, #8CC8FF);" id="captcha-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
<circle cx="8.5" cy="8.5" r="1.5"></circle>
<polyline points="21 15 16 10 5 21"></polyline>
</svg>
</div>
<input type="text" id="captcha-input" placeholder="请输入验证码" class="login-input" style="width: 100%; padding: 0.85rem 2.5rem; margin-bottom: 0; border: 2px solid transparent; border-radius: 8px; font-size: 16px; transition: all 0.3s ease; background: #f8f9fa; box-sizing: border-box;">
</div>
<canvas id="captcha-canvas" width="120" height="40" style="border: 2px solid transparent; border-radius: 8px; cursor: pointer; background: white;"></canvas>
</div>
</div>

外层容器

  • <div> - 验证码区域的容器
  • margin-bottom: 1.5rem - 下边距1.5rem
  • position: relative - 相对定位
  • width: 100% - 宽度占满父容器

Flexbox容器

  • <div style="display: flex; gap: 12px; align-items: center;"> - Flexbox布局,子元素间距12px,垂直居中对齐

验证码输入区域

  • <div style="flex: 1; position: relative;"> - 弹性增长1,相对定位

验证码图标容器

  • <div> - 验证码图标的容器
  • id="captcha-icon" - 验证码图标的唯一标识符
  • position: absolute - 绝对定位
  • left: 12px - 距离左边12px
  • top: 50% - 距离顶部50%
  • transform: translateY(-50%) - 垂直居中
  • color: var(--current-theme-color, #8CC8FF) - 图标颜色

验证码图标SVG

  • <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> - 18x18像素的验证码图标
  • <rect x="3" y="3" width="18" height="18" rx="2" ry="2"> - 矩形框
  • <circle cx="8.5" cy="8.5" r="1.5"> - 圆形,中心(8.5,8.5),半径1.5
  • <polyline points="21 15 16 10 5 21"> - 折线,连接点(21,15)、(16,10)、(5,21)

验证码输入框

  • <input type="text" id="captcha-input" placeholder="请输入验证码" class="login-input" style="..."> - 文本输入框,样式与密码框相同

验证码画布

  • <canvas id="captcha-canvas" width="120" height="40" style="border: 2px solid transparent; border-radius: 8px; cursor: pointer; background: white;"> - 120x40像素的画布
  • id="captcha-canvas" - 验证码画布的唯一标识符
  • width="120" height="40" - 画布尺寸
  • border: 2px solid transparent - 透明边框
  • border-radius: 8px - 圆角
  • cursor: pointer - 鼠标指针样式
  • background: white - 白色背景

9. 登录按钮 (Login Button)

1
<button onclick="enhancedCheckPassword()" style="width: 100%; padding: 0.85rem; background: var(--current-theme-color, #8CC8FF); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 500; cursor: pointer; transition: all 0.3s ease; text-transform: uppercase; letter-spacing: 0.5px; box-sizing: border-box;" id="login-button">登录</button>

标签解释

  • <button> - 按钮元素

属性解释

  • onclick="enhancedCheckPassword()" - 点击时执行JavaScript函数
  • id="login-button" - 登录按钮的唯一标识符

样式属性详解

  • width: 100% - 宽度占满父容器
  • padding: 0.85rem - 内边距0.85rem
  • background: var(--current-theme-color, #8CC8FF) - 背景色,使用CSS变量
  • color: white - 文字颜色白色
  • border: none - 无边框
  • border-radius: 8px - 8px圆角
  • font-size: 16px - 字体大小16px
  • font-weight: 500 - 字体粗细500(中等)
  • cursor: pointer - 鼠标指针样式
  • transition: all 0.3s ease - 所有属性0.3秒缓动过渡
  • text-transform: uppercase - 文字转换为大写
  • letter-spacing: 0.5px - 字母间距0.5px
  • box-sizing: border-box - 盒模型

内容

  • 登录 - 按钮文字

10. 错误消息 (Error Message)

1
<p id="error-msg" style="color: #EA4335; margin-top: 1rem; font-size: 0.9rem;"></p>

标签解释

  • <p> - 段落元素,用于显示错误信息

属性解释

  • id="error-msg" - 错误消息的唯一标识符

样式属性详解

  • color: #EA4335 - 红色文字颜色
  • margin-top: 1rem - 上边距1rem
  • font-size: 0.9rem - 字体大小0.9rem

背景漂浮小球 - 详细变量和函数解释

1. 小球生成函数 (createBubbles)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function createBubbles(themeColor = null) {
const container = document.getElementById('bubbles-container');
if (!container) return;

// 清除现有的圆形
container.innerHTML = '';

// 获取当前主题色
let currentTheme = themeColor;
if (!currentTheme) {
// 根据当前时间计算主题色
const currentHour = new Date().getHours();
// ... 时间主题色逻辑
}

// 基于当前主题色生成颜色变体
const themeColors = generateBubbleColors(currentTheme);
const bubbleCount = 15; // 圆形数量

for (let i = 0; i < bubbleCount; i++) {
const bubble = document.createElement('div');

// 随机大小、位置和透明度
const size = Math.random() * 150 + 50; // 50-200px
const x = Math.random() * 100; // 0-100%
const y = Math.random() * 100; // 0-100%
const opacity = Math.random() * 0.4 + 0.1; // 0.1-0.5
const color = themeColors[Math.floor(Math.random() * themeColors.length)];

// 设置圆形样式
bubble.style.cssText = `...`;

// 存储圆形的原始位置和移动速度
bubble.dataset.originalX = x;
bubble.dataset.originalY = y;
bubble.dataset.speedX = (Math.random() - 0.5) * 0.5; // -0.25 到 0.25
bubble.dataset.speedY = (Math.random() - 0.5) * 0.5; // -0.25 到 0.25

container.appendChild(bubble);
}
}

函数参数

  • themeColor = null - 主题色参数,默认为null

局部变量详解

  • container - 获取小球容器的DOM元素
  • currentTheme - 当前主题色
  • currentHour - 当前小时数
  • themeColors - 基于主题色生成的颜色数组
  • bubbleCount - 小球数量,固定为15个

循环变量

  • i - 循环计数器
  • bubble - 新创建的小球DOM元素

随机属性变量

  • size - 小球尺寸,范围50-200px
  • x - 水平位置,范围0-100%
  • y - 垂直位置,范围0-100%
  • opacity - 透明度,范围0.1-0.5
  • color - 随机选择的颜色

数据属性

  • bubble.dataset.originalX - 存储原始X坐标
  • bubble.dataset.originalY - 存储原始Y坐标
  • bubble.dataset.speedX - 存储X方向速度,范围-0.25到0.25
  • bubble.dataset.speedY - 存储Y方向速度,范围-0.25到0.25

2. 小球动画函数 (animateBubbles)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function animateBubbles() {
const bubbles = document.querySelectorAll('#bubbles-container > div');
if (!bubbles.length) return;

bubbles.forEach(bubble => {
// 获取当前位置和速度
let x = parseFloat(bubble.dataset.originalX);
let y = parseFloat(bubble.dataset.originalY);
const speedX = parseFloat(bubble.dataset.speedX);
const speedY = parseFloat(bubble.dataset.speedY);

// 更新位置
x = (x + speedX + 100) % 100;
y = (y + speedY + 100) % 100;

// 应用变换
bubble.style.left = `${x}%`;
bubble.style.top = `${y}%`;

// 保存更新后的位置
bubble.dataset.originalX = x;
bubble.dataset.originalY = y;
});

requestAnimationFrame(animateBubbles);
}

局部变量详解

  • bubbles - 所有小球元素的NodeList
  • bubble - 单个小球元素(forEach循环参数)

位置和速度变量

  • x - 当前X坐标(可修改)
  • y - 当前Y坐标(可修改)
  • speedX - X方向速度(常量)
  • speedY - Y方向速度(常量)

位置更新逻辑

  • (x + speedX + 100) % 100 - 添加100是为了处理负数,然后取模确保在0-100范围内
  • (y + speedY + 100) % 100 - 同样的逻辑应用于Y坐标

3. 颜色生成函数 (generateBubbleColors)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function generateBubbleColors(baseColor) {
if (!baseColor.startsWith('#')) {
return ['#333333', '#666666', '#999999', '#555555', '#777777', '#444444', '#888888'];
}

const r = parseInt(baseColor.slice(1, 3), 16);
const g = parseInt(baseColor.slice(3, 5), 16);
const b = parseInt(baseColor.slice(5, 7), 16);

return [
baseColor, // 原始颜色
// 变亮20%
`#${Math.min(255, Math.floor(r * 1.2)).toString(16).padStart(2, '0')}${Math.min(255, Math.floor(g * 1.2)).toString(16).padStart(2, '0')}${Math.min(255, Math.floor(b * 1.2)).toString(16).padStart(2, '0')}`,
// 变暗20%
`#${Math.max(0, Math.floor(r * 0.8)).toString(16).padStart(2, '0')}${Math.max(0, Math.floor(g * 0.8)).toString(16).padStart(2, '0')}${Math.max(0, Math.floor(b * 0.8)).toString(16).padStart(2, '0')}`,
// 其他颜色变体...
];
}

函数参数

  • baseColor - 基础颜色,十六进制格式

局部变量详解

  • r - 红色分量,从十六进制字符串中提取并转换为十进制
  • g - 绿色分量
  • b - 蓝色分量

颜色处理逻辑

  • baseColor.slice(1, 3) - 提取红色分量(跳过#符号)
  • parseInt(..., 16) - 将十六进制字符串转换为十进制整数
  • Math.min(255, ...) - 确保不超过255的最大值
  • Math.max(0, ...) - 确保不低于0的最小值
  • .toString(16) - 转换回十六进制字符串
  • .padStart(2, '0') - 确保至少2位,不足用0填充

4. 鼠标交互函数 (addMouseInteraction)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function addMouseInteraction() {
const bubbles = document.querySelectorAll('#bubbles-container > div');
if (!bubbles.length) return;

document.addEventListener('mousemove', (e) => {
const mouseX = e.clientX;
const mouseY = e.clientY;
const threshold = 200; // 鼠标影响范围

bubbles.forEach(bubble => {
const bubbleRect = bubble.getBoundingClientRect();
const bubbleX = bubbleRect.left + bubbleRect.width / 2;
const bubbleY = bubbleRect.top + bubbleRect.height / 2;

// 计算鼠标和圆形之间的距离
const dx = mouseX - bubbleX;
const dy = mouseY - bubbleY;
const distance = Math.sqrt(dx * dx + dy * dy);

// 如果圆形在鼠标影响范围内,则移动它
if (distance < threshold) {
const force = (threshold - distance) / threshold; // 力量与距离成反比
const angle = Math.atan2(dy, dx);

// 计算移动方向(远离鼠标)
const moveX = Math.cos(angle + Math.PI) * force * 30; // 远离鼠标的方向
const moveY = Math.sin(angle + Math.PI) * force * 30;

bubble.style.transform = `translate(-50%, -50%) translate(${moveX}px, ${moveY}px)`;
} else {
// 如果远离鼠标,恢复原始位置
bubble.style.transform = 'translate(-50%, -50%)';
}
});
});
}

局部变量详解

  • bubbles - 所有小球元素
  • e - 鼠标移动事件对象

鼠标位置变量

  • mouseX - 鼠标X坐标
  • mouseY - 鼠标Y坐标
  • threshold - 鼠标影响范围,200像素

小球位置变量

  • bubbleRect - 小球的位置和尺寸信息
  • bubbleX - 小球中心X坐标
  • bubbleY - 小球中心Y坐标

距离计算变量

  • dx - X方向距离差
  • dy - Y方向距离差
  • distance - 欧几里得距离

移动计算变量

  • force - 移动力量,与距离成反比
  • angle - 角度,使用Math.atan2计算
  • moveX - X方向移动距离
  • moveY - Y方向移动距离

5. 小球破裂动画函数 (animateBubblesBurst)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function animateBubblesBurst() {
const bubbles = document.querySelectorAll('#bubbles-container > div');
if (!bubbles.length) return;

bubbles.forEach((bubble, index) => {
// 延迟动画,使破裂有层次感
setTimeout(() => {
bubble.style.transition = 'all 0.6s ease-out';
bubble.style.transform = `translate(-50%, -50%) scale(1.5)`;
bubble.style.opacity = '0';
bubble.style.filter = 'blur(10px)';
}, index * 50);
});

// 动画结束后移除圆形
setTimeout(() => {
document.getElementById('bubbles-container').innerHTML = '';
}, 1000);
}

局部变量详解

  • bubbles - 所有小球元素
  • bubble - 单个小球元素
  • index - 小球在数组中的索引

动画延迟

  • index * 50 - 每个小球延迟50毫秒,创造层次感

动画属性

  • transition: 'all 0.6s ease-out' - 所有属性0.6秒缓出过渡
  • transform: 'translate(-50%, -50%) scale(1.5)' - 保持居中并放大1.5倍
  • opacity: '0' - 透明度变为0
  • filter: 'blur(10px)' - 模糊效果10像素

清理延迟

  • 1000 - 1秒后清理所有小球

6. 磨砂背景消失动画函数 (animateFrostedBgFadeOut)

1
2
3
4
5
6
7
8
function animateFrostedBgFadeOut() {
const frostedBg = document.getElementById('frosted-bg');
if (!frostedBg) return;

frostedBg.style.transition = 'all 1.5s ease-out';
frostedBg.style.opacity = '0';
frostedBg.style.backdropFilter = 'blur(0px)';
}

局部变量详解

  • frostedBg - 磨砂背景元素

动画属性

  • transition: 'all 1.5s ease-out' - 所有属性1.5秒缓出过渡
  • opacity: '0' - 透明度变为0
  • backdropFilter: 'blur(0px)' - 背景模糊效果消失

总结

这个登录系统通过精心设计的HTML结构、CSS样式和JavaScript逻辑,实现了一个功能完整、视觉效果丰富的登录界面。每个标签和变量都有其特定的作用和意义,共同构成了一个现代化的用户体验。