A simple, lightweight jQuery plugin to make slot machine animation effect.
[Check the example page!] (http://josex2r.github.io/jQuery-SlotMachine/)
Include the script after the jQuery library:
<script src="/path/to/jquery.slotmachine.js"></script>
Creating the machine:
var machine = $(foo).slotMachine( params );
Shuffle:
machine.shuffle( repeat, onStopCallback ); //No args to make rotate infinitely
Change the selected element:
machine.prev(); //Previous element
machine.next(); //Next element
Get selected element:
machine.active(); //Returns element index inside an object
Check if the machine is running:
machine.isRunning(); //Returns boolean
Change spin result, if the returned value is out of bounds, the element will be randomly choosen:
machine.setRandomize(foo); //foo must be a function (should return int) or an int
Params must be an object, optionally containing the next parammeters:
Set the first element
active: 0
Set spin animation time
delay: 200
Pass an int as miliseconds to make the machine auto rotate
repeat: false
stopHidden
Stop animation if the element is above or below the screen
stopHidden: true
Pass a function to select your own random element. This function must return an integer between 0 (first element) and max number of elements.
randomize: function(activeElementIndex){} //activeElementIndex = current selected index
Example (this machine always shows first element):
$('#foo').slotMachine({
randomize : function(activeElementIndex){
return 0;
}
});
##License
jQuery-SlotMachine is released under the MIT License.