Skip to content

Commit

Permalink
using requestAnimationFrame if available
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbbottam committed Aug 23, 2015
1 parent e96e5d6 commit ed74517
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/slot-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ var MIN_SPEED = 12;
var SPIN_COUNT = 10;
var Reel = require('./reel');

/* istanbul ignore next */
window.requestAnimationFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ) {
window.setTimeout(callback, 1000 / 60);
};
})();

/**
* returns a SlotMachine.
* @class SlotMachine
Expand Down Expand Up @@ -143,9 +153,9 @@ function spin(index) {
if (reel.currentPosition < reel.stopPosition) {
reel.spinning = true;
reel.node.style.backgroundPosition = '0px ' + reel.currentPosition + 'px';
setTimeout(function() {
window.requestAnimationFrame(function() {
spin.bind(this)(index);
}.bind(this), 1000 / 60);
}.bind(this));
} else {
reel.spinning = false;
/* set the background-position-y to stopPosition */
Expand Down

0 comments on commit ed74517

Please sign in to comment.