Skip to content

Commit

Permalink
fix requestAnimationFrame polyfill for Matter.Runner, closes #252
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jun 26, 2016
1 parent 3452465 commit 7c8f6ce
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,26 @@ var Common = require('./Common');

if (typeof window !== 'undefined') {
_requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame || window.msRequestAnimationFrame
|| function(callback){ window.setTimeout(function() { callback(Common.now()); }, 1000 / 60); };
|| window.mozRequestAnimationFrame || window.msRequestAnimationFrame;

_cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame
|| window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
}

if (!_requestAnimationFrame) {
var _frameTimeout;

_requestAnimationFrame = function(callback){
_frameTimeout = setTimeout(function() {
callback(Common.now());
}, 1000 / 60);
};

_cancelAnimationFrame = function() {
clearTimeout(_frameTimeout);
};
}

/**
* Creates a new Runner. The options parameter is an object that specifies any properties you wish to override the defaults.
* @method create
Expand Down

0 comments on commit 7c8f6ce

Please sign in to comment.