From f9a678d1d55836e0df8c0502933f23a83d73d925 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Fri, 5 Sep 2025 14:00:33 +0800 Subject: [PATCH] update --- floating-title.js | 57 +++++++++++++++++++++++++++++++++++++++++ index.html | 4 ++- public/images/1.jpg | Bin 0 -> 4957 bytes public/images/2.jpg | Bin 0 -> 26369 bytes public/images/3.jpg | Bin 0 -> 72313 bytes public/images/4.jpg | Bin 0 -> 2313 bytes public/images/5.jpg | Bin 0 -> 1625 bytes rain-icons.js | 60 ++++++++++++++++++++++++++++++++++++++++++++ style.css | 38 ++++++++++++++++++++++++++++ 9 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 floating-title.js create mode 100644 public/images/1.jpg create mode 100644 public/images/2.jpg create mode 100644 public/images/3.jpg create mode 100644 public/images/4.jpg create mode 100644 public/images/5.jpg create mode 100644 rain-icons.js diff --git a/floating-title.js b/floating-title.js new file mode 100644 index 0000000..71a4cdd --- /dev/null +++ b/floating-title.js @@ -0,0 +1,57 @@ +// 标题飘动动画,边缘碰撞 +window.addEventListener('DOMContentLoaded', () => { + const title = document.getElementById('floating-title'); + if (!title) return; + + let x = 50, y = 50; + let vx = 1.2, vy = 0.8; + let ax = 0, ay = 0; + let lastChange = Date.now(); + + function randomizeVelocity() { + // 每隔一段时间随机微调速度,模拟自然漂浮 + if (Date.now() - lastChange > 1200) { + vx += (Math.random() - 0.5) * 0.6; + vy += (Math.random() - 0.5) * 0.6; + // 限制最大速度,避免太快 + vx = Math.max(-2, Math.min(2, vx)); + vy = Math.max(-1.5, Math.min(1.5, vy)); + lastChange = Date.now(); + } + } + + const updatePosition = () => { + const ww = window.innerWidth; + const wh = window.innerHeight; + const rect = title.getBoundingClientRect(); + + randomizeVelocity(); + + // 缓动效果 + x += vx; + y += vy; + + // 边缘碰撞检测,带一点弹性和缓冲 + if (x <= 0) { + x = 0; + vx = Math.abs(vx) * (0.7 + Math.random() * 0.3); + } + if (x + rect.width >= ww) { + x = ww - rect.width; + vx = -Math.abs(vx) * (0.7 + Math.random() * 0.3); + } + if (y <= 0) { + y = 0; + vy = Math.abs(vy) * (0.7 + Math.random() * 0.3); + } + if (y + rect.height >= wh) { + y = wh - rect.height; + vy = -Math.abs(vy) * (0.7 + Math.random() * 0.3); + } + + title.style.left = x + 'px'; + title.style.top = y + 'px'; + requestAnimationFrame(updatePosition); + }; + updatePosition(); +}); diff --git a/index.html b/index.html index 2b0930d..159c3e1 100644 --- a/index.html +++ b/index.html @@ -77,7 +77,7 @@