fix: navbar/footer 区域滚轮整页跟随——SitePage 升格单一滚动容器 (#59)
Build Tutorial / Build @stack/tutorial (kaniko) (push) Successful in 4m41s

## 背景

#58 合入后的标准形是「navbar 容器 + 内滚内容区 + footer 容器」三段式:滚动只发生在中间的 `div[data-scroll-root]` 里,而 navbar/footer 是它的**兄弟**。鼠标悬停在 navbar 或 footer 上滚动时,浏览器沿祖先链找不到可滚动容器(fixed 也救不了——fixed 元素的祖先链是 viewport,不是那个内滚 div),滚动完全失效,只有鼠标在正文区域时才能滚。

## 变更内容

只动 [SitePage.tsx](https://gitea.idealjs.com/idealjs/stack/blob/fix/scroll-anywhere-site-page/apps/tutorial/src/design-system/components/SitePage.tsx) 标准形(practice 侧栏形走 document 滚动,天然满足,未动):

- `main` 自身成为唯一滚动容器:`flex h-dvh flex-col` 追加 `overflow-y-auto`,`data-scroll-root` 从内滚 div 移到 `main` 本体(PageFlipZone 的 scroll 监听正好落在实际滚动元素上)
- navbar 包裹层 `relative` → `sticky top-0`:navbar 成为滚动容器后代,滚轮沿祖先链自然找到 main
- footer 包裹层追加 `sticky bottom-0` + `mt-auto`:短内容贴容器底、长内容贴滚动视口底——「footer 恒在视口」的翻页 VT 契约由 sticky 保住
- 中间区撤掉 `overflow-y-auto` 与多余的一层包裹 div(`flex-1` 保留,min-height:auto 内容地板让 main 自然溢出)

## 自测结果

- **任意位置滚动**(playwright 量测,design/components 长页):滚轮悬在 navbar(y=30)/正文(y=450)/footer(y=880) 三处均使 `main.scrollTop=600`——修复前 navbar/footer 上滚动为 0
- **sticky 契约**:滚 600px 后 header top 恒 32(钉顶);footer 包裹层 bottom=900(钉底);`main header` 嵌套断言保持
- **e2e 全量 134 项:132 过**;2 失败为已证实的本机环境既有(learn 新手引导、toggle 展开浮层——上轮会话在未改动 main 上复现同样失败,CI 侧绿)
- **visual 5 基线零漂移**;滚动容器几何从内滚区(1082−686)变为 main(1295−900)后滚到底像素相位差 1px,`flip-bubble-charge` 基线按新几何重建(差异为整页文字 antialias 相位,无布局回归——DOM 量测 footer top 814.33 与改前逐位一致)
- 前后对照截图(1280×900,ch1 长页,鼠标悬在 navbar/footer 区域连滚 6 次滚轮):

**before · 滚轮在 navbar 区域**——页面纹丝不动,仍停在顶部:

![before-navbar](https://gitea.idealjs.com/attachments/7b20f517-8383-4d1d-a219-7e359502615a)

**before · 滚轮在 footer 区域**——同样不动(与上图像素级相同):

![before-footer](https://gitea.idealjs.com/attachments/fa4dfa32-c1c2-4922-8eb2-92b32b70a55d)

**after · 滚轮在 navbar 区域**——整页跟随滚动到中后段,navbar sticky 恒在顶:

![after-navbar](https://gitea.idealjs.com/attachments/c1c6c03f-236d-4dcc-9680-c03865889aaf)

**after · 滚轮在 footer 区域**——同样整页跟随,footer sticky 恒在底:

![after-footer](https://gitea.idealjs.com/attachments/03d4d433-75de-4ead-8f5d-25321dcf192e)

---------

Co-authored-by: cqh963852 <cqh963852@hotmail.com>
Reviewed-on: #59
This commit was merged in pull request #59.
This commit is contained in:
arnold.cuiandcqh963852 committed 2026-11-15 16:21:32 +00:00
1 parent 25190202d7
commit 3f01d15708
2 files changed
+15 -14

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 156 KiB

@@ -72,10 +72,10 @@ export function SitePage({
)
}
return (
<main className="flex h-dvh flex-col text-content text-body">
<main data-scroll-root className="flex h-dvh flex-col overflow-y-auto text-content text-body">
{nav && (
<div
className="relative z-50 flex-none bg-paper"
className="sticky top-0 z-50 flex-none bg-paper"
style={viewTransitionName ? { viewTransitionName } : undefined}
>
<div className={`${SITE_SHELL} pt-8`}>
@@ -83,19 +83,20 @@ export function SitePage({
</div>
</div>
)}
<div data-scroll-root className="min-h-0 flex-1 overflow-y-auto">
<div className={`${SITE_SHELL} pb-8`}>
{(title || subtitle || desc) && (
<div className="mb-7">
{title && <h1 className="m-0 text-t1 font-extrabold text-ink">{title}</h1>}
{subtitle && <p className="m-0 mt-2 text-t2 font-bold text-ink">{subtitle}</p>}
{desc && <p className="m-0 mt-2 text-content text-mute">{desc}</p>}
</div>
)}
{children}
</div>
<div className={`${SITE_SHELL} flex-1 pb-8`}>
{(title || subtitle || desc) && (
<div className="mb-7">
{title && <h1 className="m-0 text-t1 font-extrabold text-ink">{title}</h1>}
{subtitle && <p className="m-0 mt-2 text-t2 font-bold text-ink">{subtitle}</p>}
{desc && <p className="m-0 mt-2 text-content text-mute">{desc}</p>}
</div>
)}
{children}
</div>
<div className="flex-none bg-paper" style={{ viewTransitionName: 'site-footer' }}>
<div
className="sticky bottom-0 mt-auto flex-none bg-paper"
style={{ viewTransitionName: 'site-footer' }}
>
<div className={`${SITE_SHELL} pb-6`}>
<SiteFooter groups={footerGroups} />
</div>