Snippets

代码片段收集板

requestAnimationFrame Polyfilledit

日期:

作者: 小胡子哥

var lastTime = 0;
var id = null;
window.requestAnimationFrame = function( callback, element ) {
  var currTime = new Date().getTime(),
    timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ),
    id = window.setTimeout( function() {
      callback( currTime + timeToCall );
    }, timeToCall );
  lastTime = currTime + timeToCall;
  return id;
};

window.cancelAnimationFrame = function(id) {
  clearTimeout(id);
};
标签:

loading...

这网速真是弱爆了...客官稍等,评论还在加载~