Files
WAI_Project_UNIX/cool/scroller/index.ts
2025-08-11 23:48:02 +08:00

24 lines
477 B
TypeScript

import { router } from "../router";
class Scroller {
list: Map<string, ((top: number) => void)[]> = new Map();
// 触发滚动
emit(top: number) {
const cbs = this.list.get(router.path()) ?? [];
cbs.forEach((cb) => {
cb(top);
});
}
// 监听页面滚动
on(callback: (top: number) => void) {
const path = router.path();
const cbs = this.list.get(path) ?? [];
cbs.push(callback);
this.list.set(path, cbs);
}
}
export const scroller = new Scroller();