2019-01-12 03:33:27 +00:00
|
|
|
import getRequestAnimationFrame, {
|
|
|
|
cancelRequestAnimationFrame as caf,
|
|
|
|
} from './getRequestAnimationFrame';
|
|
|
|
const raf = getRequestAnimationFrame();
|
2018-02-04 03:08:04 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export const cancelAnimationTimeout = frame => caf(frame.id);
|
2018-02-04 03:08:04 +00:00
|
|
|
|
|
|
|
export const requestAnimationTimeout = (callback, delay) => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const start = Date.now();
|
|
|
|
function timeout() {
|
2018-02-04 03:08:04 +00:00
|
|
|
if (Date.now() - start >= delay) {
|
2019-01-12 03:33:27 +00:00
|
|
|
callback.call();
|
2018-02-04 03:08:04 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
frame.id = raf(timeout);
|
2018-02-04 03:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const frame = {
|
|
|
|
id: raf(timeout),
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-02-04 03:08:04 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
return frame;
|
|
|
|
};
|