Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Last active August 29, 2015 14:15
Show Gist options
  • Save mohayonao/5446bcc253b944c42c61 to your computer and use it in GitHub Desktop.
Save mohayonao/5446bcc253b944c42c61 to your computer and use it in GitHub Desktop.
var AnimationTimer = {};
var _timerId = 0;
var _timerIds = {};
AnimationTimer.setInterval = function(callback, delay) {
var timerId = ++_timerId;
_timerIds[timerId] = setTimeout(function interval() {
requestAnimationFrame(function() {
callback();
_timerIds[timerId] = setTimeout(interval, delay);
});
}, delay);
return timerId;
};
AnimationTimer.clearInterval = function(timerId) {
clearTimeout(_timerIds[timerId]);
};
AnimationTimer.setTimeout = function(callback, delay) {
var timerId = ++_timerId;
_timerIds[timerId] = setTimeout(function() {
requestAnimationFrame(function() {
callback();
});
}, delay);
return timerId;
};
AnimationTimer.clearTimeout = function(timerId) {
clearTimeout(_timerIds[timerId]);
};
module.exports AnimationTimer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment