Last active
August 29, 2015 14:15
-
-
Save mohayonao/5446bcc253b944c42c61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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