Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. function Animation(context){
  2. var nativeRequest, nativeCancel;
  3. this.context = context;
  4. this.vendors = ['ms', 'moz', 'webkit', 'o'];
  5. this.performance = this.performance();
  6. this.startTime = +new Date();
  7. this.lastTime = +new Date();
  8. this.now = this.performance.now||this.now;
  9. for(var x=0; x<this.vendors.length; x++){
  10. nativeRequest = window[this.vendors[x]+'RequestAnimationFrame'];
  11. nativeCancel = window[this.vendors[x]+'CancelAnimationFrame']||window[this.vendors[x]+'CancelRequestAnimationFrame'];
  12. }
  13. this.request = nativeRequest||this.request;
  14. this.cancel = nativeCancel||this.cancel;
  15. }
  16.  
  17. Animation.prototype.request = function(callback){
  18. var currentTime, delay, _ = this;
  19. currentTime = +new Date();
  20. delay = 16 + _.lastTime - currentTime;
  21. delay = delay < 0 ? 0 : delay;
  22. _.lastTime = currentTime;
  23. return window.setTimeout(function(){
  24. _.lastTime = +new Date();
  25. callback(performance.now());
  26. }, delay);
  27. };
  28.  
  29. Animation.prototype.cancel = function(id){
  30. window.clearTimeout(id);
  31. };
  32.  
  33. Animation.prototype.performance = function(){
  34. return window.performance && window.performance.now ? window.performance : {};
  35. };
  36.  
  37. Animation.prototype.now = function(id){
  38. return +new Date() - this.startTime;
  39. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement