mirror of
https://github.com/youzan/vant.git
synced 2026-01-28 01:10:04 +08:00
chore: move useCountdown to @vant/use
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* requestAnimationFrame polyfill
|
||||
*/
|
||||
|
||||
import { inBrowser } from '../base';
|
||||
|
||||
let prev = Date.now();
|
||||
|
||||
function fallback(fn: FrameRequestCallback): number {
|
||||
const curr = Date.now();
|
||||
const ms = Math.max(0, 16 - (curr - prev));
|
||||
const id = setTimeout(fn, ms);
|
||||
prev = curr + ms;
|
||||
return id;
|
||||
}
|
||||
|
||||
const root = (inBrowser ? window : global) as Window;
|
||||
|
||||
const iRaf = root.requestAnimationFrame || fallback;
|
||||
|
||||
const iCancel = root.cancelAnimationFrame || root.clearTimeout;
|
||||
|
||||
export function raf(fn: FrameRequestCallback): number {
|
||||
return iRaf.call(root, fn);
|
||||
}
|
||||
|
||||
// double raf for animation
|
||||
export function doubleRaf(fn: FrameRequestCallback): void {
|
||||
raf(() => {
|
||||
raf(fn);
|
||||
});
|
||||
}
|
||||
|
||||
export function cancelRaf(id: number) {
|
||||
iCancel.call(root, id);
|
||||
}
|
||||
@@ -3,7 +3,6 @@ export * from './create';
|
||||
export * from './format/unit';
|
||||
export * from './format/number';
|
||||
export * from './format/string';
|
||||
export * from './dom/raf';
|
||||
export * from './dom/style';
|
||||
export * from './dom/event';
|
||||
export * from './dom/scroll';
|
||||
|
||||
Reference in New Issue
Block a user