mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Update scroll to top
This commit is contained in:
@ -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);
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user