Guest User

merry1

a guest
Feb 8th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     var lastTime = 0;
  3.     var vendors = ['ms', 'moz', 'webkit', 'o'];
  4.     for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  5.         window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
  6.         window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
  7.                                    || window[vendors[x]+'CancelRequestAnimationFrame'];
  8.     }
  9.  
  10.     if (!window.requestAnimationFrame)
  11.         window.requestAnimationFrame = function(callback, element) {
  12.             var currTime = new Date().getTime();
  13.             var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  14.             var id = window.setTimeout(function() { callback(currTime + timeToCall); },
  15.               timeToCall);
  16.             lastTime = currTime + timeToCall;
  17.             return id;
  18.         };
  19.  
  20.     if (!window.cancelAnimationFrame)
  21.         window.cancelAnimationFrame = function(id) {
  22.             clearTimeout(id);
  23.         };
  24. }());
Advertisement
Add Comment
Please, Sign In to add comment