Skip to content

Instantly share code, notes, and snippets.

@senola
Last active January 20, 2017 02:41
Show Gist options
  • Save senola/3cc4115c6a0df90feff6acb00c5fdd34 to your computer and use it in GitHub Desktop.
Save senola/3cc4115c6a0df90feff6acb00c5fdd34 to your computer and use it in GitHub Desktop.
requestAnimationFrame兼容写法
window.requestAnimationFrame =
window.__requestAnimationFrame ||
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
(function () {
return function (callback, element) {
var lastTime = element.__lastTime;
if (lastTime === undefined) {
lastTime = 0;
}
var currTime = Date.now();
var timeToCall = Math.max(1, 33 - (currTime - lastTime));
window.setTimeout(callback, timeToCall);
element.__lastTime = currTime + timeToCall;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment