Skip to content

Instantly share code, notes, and snippets.

@caubry
Last active August 29, 2015 13:56
Show Gist options
  • Save caubry/9003659 to your computer and use it in GitHub Desktop.
Save caubry/9003659 to your computer and use it in GitHub Desktop.
requestId: 0,
move: function() {
var _this = this;
if (this.requestId === 0) {
(function animationLoop() {
_this.render();
_this.requestId = requestAnimationFrame(animationLoop, _this.move);
})();
}
},
render: function() {
// Add some drawing
},
onKeyUp: function() {
// Cancel the animation request
if (this.requestId) {
cancelAnimationFrame(this.requestId);
}
// Allow a new request to be called
this.requestId = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment