[Improvement] Tab animation fluency && position (#379)

This commit is contained in:
neverland
2017-12-05 20:23:34 +08:00
committed by GitHub
parent 2327e75516
commit 5a17bc520a
12 changed files with 199 additions and 393 deletions

32
packages/utils/raf.js Normal file
View File

@@ -0,0 +1,32 @@
/**
* requestAnimationFrame polyfill
*/
import { isServer } from './index';
let prev = Date.now();
function fallback(fn) {
const curr = Date.now();
const ms = Math.max(0, 16 - (curr - prev));
const id = setTimeout(fn, ms);
prev = curr + ms;
return id;
}
const global = isServer ? global : window;
const iRaf =
global.requestAnimationFrame ||
global.webkitRequestAnimationFrame ||
fallback;
const iCancel =
global.cancelAnimationFrame ||
global.webkitCancelAnimationFrame ||
global.clearTimeout;
export function raf(fn) {
return iRaf.call(global, fn);
}
export function cancel(id) {
iCancel.call(global, id);
}