mirror of
https://github.com/zoriya/v10.git
synced 2026-08-07 22:56:34 +00:00
14 lines
357 B
TypeScript
14 lines
357 B
TypeScript
/**
|
|
* Request an animation frame with cleanup.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const cancel = animationFrame((time) => console.log('Frame at', time));
|
|
* cancel(); // Cancel if needed
|
|
* ```
|
|
*/
|
|
export function animationFrame(callback: FrameRequestCallback): () => void {
|
|
const id = requestAnimationFrame(callback);
|
|
return () => cancelAnimationFrame(id);
|
|
}
|