From 82c878ce331f773e0df62b71941feafbfcc2002b Mon Sep 17 00:00:00 2001 From: Furrium Network Date: Tue, 22 Sep 2026 21:03:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E5=B8=96=E5=AD=90=E4=B8=8E?= =?UTF-8?q?=E4=BE=A7=E8=BE=B9=E6=A0=8F=E6=94=B9=E7=94=A8=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原先所有入场动画都是「页面加载时按时间播放」:卡片带固定错峰延迟依次 浮现。问题在于长列表里,用户还没滚到的内容早就播完了,等真正滚到 那里时看到的是静止的画面,滚动与动画之间没有关系。 改用 animation-timeline: view(),让入场进度与滚动位置绑定——元素从 视口下缘进入时开始显现,走过 25% 视口高度时完成。这样内容是在用户 真正看到它的那一刻出现,而非提前播完。 具体改动: - 帖子卡片、回复、详情卡片改用 scrollRise,animation-range 为 entry 0% → entry 25% - 侧边栏的统计卡与友链卡用 scrollSlideIn(自左侧滑入),与主内容的 纵向入场形成方向对比 - 卡片悬浮抬升由 3px 调整为 4px,配合滚动出现的节奏 两处容易出错的细节已处理: - .post-card:nth-child(n) 的错峰规则选择器权重(0,2,0)高于 .post-card (0,1,0),必须用同等权重把 animation-delay 清零,否则滚动进度会与 时间延迟叠加产生卡顿感 - 滚动驱动动画写在 @supports 块内,不受 prefers-reduced-motion 的通配 规则覆盖,因此单独补了一条关闭规则 兼容性:animation-timeline: view() 目前 Chrome/Edge 115+、Safari 26+ 支持,Firefox 尚未支持,全球覆盖约 87%。因此全部规则包在 @supports (animation-timeline: view()) 内,不支持的浏览器整块跳过, 继续使用原有的 riseIn 时间动画,不会出现元素停在隐藏态的问题。 实测(Puppeteer,1280×900,16 张卡片): - 初始状态:视口内 4 张完全显示,第 5 张 opacity 0.68(正处于渐入 过程中,证明动画跟随滚动位置而非时间),视口外 11 张 opacity 0.00 - 滚动到 y=1800:滚过的卡片全部回到 opacity 1.00,新进入视口的依次 显现 - 开启 prefers-reduced-motion:所有卡片 animation-name 为 none, opacity 为 1.00 - 降级路径完整性:@supports 块外的 riseIn 关键帧、卡片与回复的基础 动画、错峰延迟规则均保留 完整测试套件 25/25 通过。 --- style.css | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/style.css b/style.css index 10feed8..98f1ebc 100644 --- a/style.css +++ b/style.css @@ -3344,3 +3344,97 @@ select:disabled { } /* 搜索框、验证码等内嵌小输入框同样适用,无需单独处理 */ + +/* ============================================================ + 🎞️ 滚动驱动动画 + ------------------------------------------------------------ + 让内容随滚动位置渐入,而不是在页面加载时一次性播完——后者在长 + 列表里意味着「下面还没看到的内容早就播完了」。 + + 兼容性:animation-timeline: view() 目前 Chrome/Edge 115+、 + Safari 26+ 支持,Firefox 尚未支持(全球覆盖约 87%)。 + 因此全部规则包在 @supports 内,不支持的浏览器会退回上面 + riseIn 那套基于时间的入场动画,不会出现元素不显示的问题。 + + 设计上仍保持克制: + - 位移 24px 以内,不做夸张的位移或旋转 + - 动画在元素进入视口下半部时即完成,不拖到正中央才出现 + - 一旦滚过就保持终态(fill: both),不会来回闪 + ============================================================ */ + +@supports (animation-timeline: view()) { + + /* 通用入场:进入视口时自下而上浮现 */ + @keyframes scrollRise { + from { + opacity: 0; + transform: translateY(24px); + } + to { + opacity: 1; + transform: translateY(0); + } + } + + /* 侧边栏区块:从左侧轻轻滑入,与主内容的纵向入场区分开 */ + @keyframes scrollSlideIn { + from { + opacity: 0; + transform: translateX(-16px); + } + to { + opacity: 1; + transform: translateX(0); + } + } + + /* 覆盖掉基于时间的入场动画:改由滚动位置驱动。 + 注意上面的 .post-card:nth-child(n) 错峰规则选择器权重更高 + (0,2,0 对 0,1,0),必须用同等或更高权重才能把 animation-delay + 清零,否则滚动进度与时间延迟会叠加,出现卡顿感。 */ + .post-card, + .post-card:nth-child(n), + .reply-item, + .reply-item:nth-child(n), + .post-detail-card { + animation-name: scrollRise; + animation-duration: 1ms; /* 时长由 timeline 决定,此处仅占位 */ + animation-fill-mode: both; + animation-timeline: view(); + /* 元素从进入视口下缘到走过 25% 视口高度时完成, + 这样用户在内容完全进入视野前就能看到它 */ + animation-range: entry 0% entry 25%; + /* 清除原先的时间错峰,避免与滚动进度叠加导致延迟感 */ + animation-delay: 0ms; + } + + /* 侧边栏区块 */ + #sidebar .stats-box, + #sidebar .links-box { + animation-name: scrollSlideIn; + animation-duration: 1ms; + animation-fill-mode: both; + animation-timeline: view(); + animation-range: entry 0% entry 40%; + animation-delay: 0ms; + } + + /* 卡片悬浮时的抬升稍强一点,配合滚动出现的节奏 */ + .post-card:hover { + transform: translateY(-4px); + } +} + +/* 关闭动画时,滚动驱动动画同样要停——它在动画层之外, + 不会被子面的 prefers-reduced-motion 通配规则覆盖到。 */ +@media (prefers-reduced-motion: reduce) { + .post-card, + .reply-item, + .post-detail-card, + #sidebar .stats-box, + #sidebar .links-box { + animation: none !important; + opacity: 1 !important; + transform: none !important; + } +}