You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
513 B
24 lines
513 B
import getRequestAnimationFrame, {
|
|
cancelRequestAnimationFrame as caf,
|
|
} from './getRequestAnimationFrame';
|
|
const raf = getRequestAnimationFrame();
|
|
|
|
export const cancelAnimationTimeout = frame => caf(frame.id);
|
|
|
|
export const requestAnimationTimeout = (callback, delay = 0) => {
|
|
const start = Date.now();
|
|
function timeout() {
|
|
if (Date.now() - start >= delay) {
|
|
callback.call();
|
|
} else {
|
|
frame.id = raf(timeout);
|
|
}
|
|
}
|
|
|
|
const frame = {
|
|
id: raf(timeout),
|
|
};
|
|
|
|
return frame;
|
|
};
|