Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Animation(context){
- var nativeRequest, nativeCancel;
- this.context = context;
- this.vendors = ['ms', 'moz', 'webkit', 'o'];
- this.performance = this.performance();
- this.startTime = +new Date();
- this.lastTime = +new Date();
- this.now = this.performance.now||this.now;
- for(var x=0; x<this.vendors.length; x++){
- nativeRequest = window[this.vendors[x]+'RequestAnimationFrame'];
- nativeCancel = window[this.vendors[x]+'CancelAnimationFrame']||window[this.vendors[x]+'CancelRequestAnimationFrame'];
- }
- this.request = nativeRequest||this.request;
- this.cancel = nativeCancel||this.cancel;
- }
- Animation.prototype.request = function(callback){
- var currentTime, delay, _ = this;
- currentTime = +new Date();
- delay = 16 + _.lastTime - currentTime;
- delay = delay < 0 ? 0 : delay;
- _.lastTime = currentTime;
- return window.setTimeout(function(){
- _.lastTime = +new Date();
- callback(performance.now());
- }, delay);
- };
- Animation.prototype.cancel = function(id){
- window.clearTimeout(id);
- };
- Animation.prototype.performance = function(){
- return window.performance && window.performance.now ? window.performance : {};
- };
- Animation.prototype.now = function(id){
- return +new Date() - this.startTime;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement