Skip to content

Commit 25296b4

Browse files
committed
Enabled 'stopHidden' attribute. Fixed #6
1 parent fb8800d commit 25296b4

File tree

7 files changed

+65
-51
lines changed

7 files changed

+65
-51
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Pass an int as miliseconds to make the machine auto rotate
8686

8787
repeat: false
8888

89-
### stopHidden (currently disabled)
89+
### stopHidden
9090

9191
Stop animation if the element is above or below the screen
9292

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jQuery-SlotMachine",
33
"description": "A simple jQuery plugin to make slot machine animation effect",
4-
"version": "2.0.8",
4+
"version": "2.0.9",
55
"keywords": [
66
"slots",
77
"gambling",

dist/jquery.slotmachine.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! SlotMachine - v2.0.8 - 2015-01-28
1+
/*! SlotMachine - v2.0.9 - 2015-04-21
22
* https://github.com/josex2r/jQuery-SlotMachine
33
* Copyright (c) 2015 Jose Luis Represa; Licensed MIT */
44
;(function($, window, document, undefined){
@@ -10,7 +10,7 @@
1010
auto : false, //Repeat delay [false||int]
1111
randomize : null, //Randomize function, must return an integer with the selected position
1212
complete : null, //Callback function(result)
13-
//stopHidden : true //Stops animations if the element isn´t visible on the screen
13+
stopHidden : true //Stops animations if the element isn´t visible on the screen
1414
};
1515

1616
var FX_FAST = 'slotMachineBlurFast',
@@ -363,11 +363,7 @@
363363
*/
364364
SlotMachine.prototype.shuffle = function( spins, onComplete ){
365365
var self = this;
366-
/*
367-
if(!this.isVisible() && this.settings.stopHidden === true){
368-
return this.stop();
369-
}
370-
*/
366+
371367
if(onComplete !== undefined){
372368
//this._oncompleteStack.push(onComplete);
373369
this._oncompleteStack[1] = onComplete;
@@ -409,19 +405,24 @@
409405
}
410406

411407
//Perform animation
412-
this.$container.animate({
413-
marginTop : this._maxTop
414-
}, delay, 'linear', function(){
415-
//Reset top position
416-
self.$container.css('margin-top', 0);
417-
418-
if(spins - 1 <= 0){
419-
self.stop();
420-
}else{
421-
//Repeat animation
422-
self.shuffle(spins - 1);
423-
}
424-
});
408+
if(!this.isVisible() && this.settings.stopHidden === true){
409+
spins = 0;
410+
self.stop();
411+
}else{
412+
this.$container.animate({
413+
marginTop : this._maxTop
414+
}, delay, 'linear', function(){
415+
//Reset top position
416+
self.$container.css('margin-top', 0);
417+
418+
if(spins - 1 <= 0){
419+
self.stop();
420+
}else{
421+
//Repeat animation
422+
self.shuffle(spins - 1);
423+
}
424+
});
425+
}
425426

426427
return this.futureActive;
427428
};
@@ -511,9 +512,15 @@
511512
self.futureActive = self.getNext();
512513
}
513514
self.isRunning = true;
514-
self.shuffle(5, function(){
515-
self._timer.reset();
516-
});
515+
if(!self.isVisible() && self.settings.stopHidden === true){
516+
setTimeout(function(){
517+
self._timer.reset();
518+
}, 500);
519+
}else{
520+
self.shuffle(5, function(){
521+
self._timer.reset();
522+
});
523+
}
517524

518525
}, this.settings.auto);
519526
};

dist/jquery.slotmachine.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-slotmachine",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"engines": {
55
"node": ">= 0.8.0"
66
},

slotmachine.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"winning",
1212
"machine"
1313
],
14-
"version": "2.0.8",
14+
"version": "2.0.9",
1515
"download": "https://github.com/josex2r/jQuery-SlotMachine",
1616
"homepage": "https://github.com/josex2r/jQuery-SlotMachine",
1717
"demo": "http://josex2r.github.io/jQuery-SlotMachine/",

0 commit comments

Comments
 (0)