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 { BackTopProps } from './types.js';
import { watchViewport } from './watch.js';
/*** 返回顶部:滚动越过阈值浮现,环形进度显示已滚比例,点击平滑回顶(尊重减少动效偏好) ***/
export function backTop(props: BackTopProps = {}): HTMLElement {
@@ -39,8 +40,6 @@ export function backTop(props: BackTopProps = {}): HTMLElement {
props.onClick?.();
};
scroller.addEventListener('scroll', sync, { passive: true }); // 被动监听:不阻塞滚动
window.addEventListener('resize', sync); // 视口变化会改可滚距离
sync(); // 首屏同步一次,避免刷新后停在中间位置却未浮现
watchViewport(btn, scroller, sync); // 滚动 / 缩放后同步浮现态,节点脱离文档即自摘监听
return btn;
}