Skip to content

Instantly share code, notes, and snippets.

@benqy
Forked from julianshapiro/RAF.js
Created October 19, 2015 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benqy/75bf17ec60b49d15af76 to your computer and use it in GitHub Desktop.
Save benqy/75bf17ec60b49d15af76 to your computer and use it in GitHub Desktop.
requestAnimationFrame Polyfill
var requestAnimationFrame = window.requestAnimationFrame || (function() {
var timeLast = 0;
return window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
var timeCurrent = (new Date()).getTime(),
timeDelta;
/* Dynamically set the delay on a per-tick basis to more closely match 60fps. */
/* Technique by Erik Moller. MIT license: https://gist.github.com/paulirish/1579671. */
timeDelta = Math.max(0, 16 - (timeCurrent - timeLast));
timeLast = timeCurrent + timeDelta;
return setTimeout(function() { callback(timeCurrent + timeDelta); }, timeDelta);
};
})();
@benqy
Copy link
Author

benqy commented Oct 19, 2015

超过16毫秒则立即执行.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment