fix: 详情页滚动与多余背景 — 对齐原站路由级 canvas 生命周期
- HeroScene/LoadingOverlay 仅在 "/" 渲染(原 canvas/set:详情页 reveal 后 卸载 canvas;entry 幕布是主页专属流程)——详情页不再有贴纸/背景 FX/玻璃 模型等"多余背景",也没有 loading 幕布 - 详情页滚动容器改为常规文档流:我们的 Lenis 是 window 级,原版的嵌套 overflow-y-auto 容器会吞掉滚轮导致页面不能滚动;窗口原生滚动接管 - SmoothScroller 按路由启停 Lenis(原 95212:主页 ReactLenis、详情页原生 滚动),路由切换时滚动复位到顶部(转场遮罩盖住跳变) - CDP 实测:详情页 wheel/End 滚动 ✅、canvas=0、幕布=0;返回主页后 canvas/Lenis/滚动条恢复、wheel 平滑滚动 ✅
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import Lenis from 'lenis';
|
||||
import { scrollBus, notifyScroll } from '@/lib/scrollBus';
|
||||
import { scrollEnv } from '@/lib/scrollEnv';
|
||||
@@ -21,7 +22,29 @@ const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
|
||||
* camera pull-back).
|
||||
*/
|
||||
export default function SmoothScroller() {
|
||||
// Original route wiring (chunk 3c6cc5b2 module 95212): the home route is
|
||||
// wrapped in ReactLenis; every other route scrolls its container
|
||||
// natively. Our Lenis is window-level, so on detail routes we destroy it
|
||||
// entirely (native window scroll) and reset the scroll to the top — the
|
||||
// transition overlay covers the jump.
|
||||
const pathname = usePathname();
|
||||
const isHome = pathname === '/';
|
||||
|
||||
// Scroll reset per route (original scrolls its per-route container to
|
||||
// top on mount; the transition cover hides the jump).
|
||||
useEffect(() => {
|
||||
if (window.location.hash) return;
|
||||
window.scrollTo(0, 0);
|
||||
requestAnimationFrame(() => window.scrollTo(0, 0));
|
||||
}, [isHome]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isHome) {
|
||||
scrollEnv.setLenis(null);
|
||||
return;
|
||||
}
|
||||
let disposed = false;
|
||||
let rafId = 0;
|
||||
// Refresh must always start at the top (original behavior: no anchor
|
||||
// → scroll to 0; also re-asserted on bfcache pageshow).
|
||||
if ('scrollRestoration' in window.history) {
|
||||
@@ -73,19 +96,22 @@ export default function SmoothScroller() {
|
||||
updateCameraProgress();
|
||||
|
||||
function raf(time: number) {
|
||||
if (disposed) return;
|
||||
lenis.raf(time);
|
||||
requestAnimationFrame(raf);
|
||||
rafId = requestAnimationFrame(raf);
|
||||
}
|
||||
|
||||
requestAnimationFrame(raf);
|
||||
rafId = requestAnimationFrame(raf);
|
||||
|
||||
return () => {
|
||||
disposed = true;
|
||||
cancelAnimationFrame(rafId);
|
||||
window.removeEventListener('resize', updateCameraProgress);
|
||||
window.removeEventListener('pageshow', onPageShow);
|
||||
scrollEnv.setLenis(null);
|
||||
lenis.destroy();
|
||||
};
|
||||
}, []);
|
||||
}, [isHome]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user