iter(g106): 滚动监听改为卸载自清理

This commit is contained in:
HIsheR
2026-10-26 13:58:22 +08:00
parent 7d57f261df
commit c66bcf35da
6 changed files with 31 additions and 11 deletions
+2 -3
View File
@@ -1,5 +1,6 @@
import { h } from '@ui-arch/frame';
import type { AffixProps } from './types.js';
import { watchViewport } from './watch.js';
/*** 固钉:内容滚动越过阈值后转 fixed 贴住视口顶部,外层保留占位高度避免布局跳动 ***/
export function affix(props: AffixProps, ...children: unknown[]): HTMLElement {
@@ -36,8 +37,6 @@ export function affix(props: AffixProps, ...children: unknown[]): HTMLElement {
}
};
scroller.addEventListener('scroll', sync, { passive: true }); // 被动监听,不阻塞滚动
window.addEventListener('resize', sync); // 视口变化会改判定与宽度
sync(); // 首屏同步一次:刷新时若已滚动到位,直接进入固定态
watchViewport(wrap, scroller, sync); // 滚动 / 缩放后重算,节点脱离文档即自摘监听
return wrap;
}