Update scroll to top

This commit is contained in:
DefectingCat
2022-12-12 15:24:29 +08:00
parent 7954c974da
commit a43cd50166
3 changed files with 39 additions and 20 deletions

View File

@ -102,3 +102,19 @@ export const getMousePosition = (e: MouseEvent | globalThis.TouchEvent) => {
y: e.touches[0].clientY,
};
};
type Debounce = {
<T extends unknown[], R>(fn: (...arg: T) => R, ms: number): (
this: unknown,
...arg: T
) => void;
};
export const debounce: Debounce = (fn, ms) => {
let timer: NodeJS.Timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
}, ms);
};
};