mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
21 lines
485 B
TypeScript
21 lines
485 B
TypeScript
export const inBrowser = typeof window !== 'undefined';
|
|
|
|
// Keep forward compatible
|
|
// should be removed in next major version
|
|
export const supportsPassive = true;
|
|
|
|
export function raf(fn: FrameRequestCallback): number {
|
|
return inBrowser ? requestAnimationFrame(fn) : -1;
|
|
}
|
|
|
|
export function cancelRaf(id: number) {
|
|
if (inBrowser) {
|
|
cancelAnimationFrame(id);
|
|
}
|
|
}
|
|
|
|
// double raf for animation
|
|
export function doubleRaf(fn: FrameRequestCallback): void {
|
|
raf(() => raf(fn));
|
|
}
|