Skip to content

Commit

Permalink
Fixed position on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
josex2r committed Feb 23, 2016
1 parent 1dc55da commit 500c984
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/jquery.slotmachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ class SlotMachine {
prev () {
this.futureActive = this.prevIndex;
this.running = true;
this.slide = true;
this.stop();

return this.futureActive;
Expand All @@ -521,7 +520,6 @@ class SlotMachine {
next () {
this.futureActive = this.nextIndex;
this.running = true;
this.slide = true;
this.stop();

return this.futureActive;
Expand All @@ -534,6 +532,7 @@ class SlotMachine {
*/
getDelayFromSpins (spins) {
let delay = this.settings.delay;
this._transition = 'linear';

switch (spins) {
case 1:
Expand All @@ -543,12 +542,10 @@ class SlotMachine {
break;
case 2:
delay /= 0.75;
this._transition = 'linear';
this._animationFX = FX_SLOW;
break;
case 3:
delay /= 1;
this._transition = 'linear';
this._animationFX = FX_NORMAL;
break;
case 4:
Expand All @@ -557,7 +554,6 @@ class SlotMachine {
break;
default:
delay /= 1.5;
this._transition = 'linear';
this._animationFX = FX_FAST;
}

Expand Down Expand Up @@ -585,13 +581,14 @@ class SlotMachine {
this._animate(this.direction.to);
this.raf(() => {
if (!this.stopping && this.running) {
this.resetPosition(this.direction.first);
const left = spins - 1;

if (spins - 1 <= 0) {
this.resetPosition(this.direction.first);
if (left <= 1) {
this.stop();
} else {
// Repeat animation
this.shuffle(spins - 1);
this.shuffle(left);
}
}
}, delay);
Expand All @@ -618,12 +615,10 @@ class SlotMachine {
}

// Check direction to prevent jumping
if (this.slide) {
if (this._isGoingBackward()) {
this.resetPosition(this.direction.firstToLast);
} else if (this._isGoingForward()) {
this.resetPosition(this.direction.lastToFirst);
}
if (this._isGoingBackward()) {
this.resetPosition(this.direction.firstToLast);
} else if (this._isGoingForward()) {
this.resetPosition(this.direction.lastToFirst);
}

// Update last choosen element index
Expand All @@ -637,7 +632,6 @@ class SlotMachine {
this.raf(() => {
this.stopping = false;
this.running = false;
this.slide = false;
this.futureActive = null;

this._oncompleteStack.filter((fn) => typeof fn === 'function').forEach((fn) => {
Expand Down

0 comments on commit 500c984

Please sign in to comment.