JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<ul class="slot">
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
<br />
<input type="button" value="test" id="playBtn" onclick="getluckynumber();"/>
<input type="button" id="fire" style="visibility:hidden;"/>
<input type="hidden" id="luck" value=""/>
</div>
CSS
body {
padding:3px;
}
ul {
padding: 0;
margin: 0;
list-style: none;
}
.jSlots-wrapper {
overflow: hidden;
height: 20px;
display: inline-block;
/* to size correctly, can use float too, or width*/
border: 1px solid #999;
}
.slot {
float: left;
}
JavaScript
$(document).ready(function(){
$('.slot').jSlots({
spinner:'#fire',
endNumbers:$("#luck").val()
});
});
function getluckynumber(){
$.ajax({
url:"ajax.php",
method:"POST",
data:{event_id:'122'},
})
.done(function(data){
//the returned data is a array, eg [1,3,4]
//for the spinner to stop at 134
$("#luck").val(data);
console.log($("#luck").val());
$("#fire").trigger("click");
});
}
/*
* jQuery jSlots Plugin
* http://matthewlein.com/jslot/
* Copyright (c) 2011 Matthew Lein
* Version: 1.0.2 (7/26/2012)
* Dual licensed under the MIT and GPL licenses
* Requires: jQuery v1.4.1 or later
*/
(function ($) {
$.jSlots = function (el, options) {
var base = this;
base.$el = $(el);
base.el = el;
base.$el.data("jSlots", base);
base.init = function () {
base.options = $.extend({}, $.jSlots.defaultOptions, options);
base.setup();
base.bindEvents();
};
// --------------------------------------------------------------------- //
// DEFAULT OPTIONS
// --------------------------------------------------------------------- //
$.jSlots.defaultOptions = {
number: 3, // Number: number of slots
winnerNumber: 1, // Number or Array: list item number(s) upon which to trigger a win, 1-based index, NOT ZERO-BASED
spinner: '', // CSS Selector: element to bind the start event to
spinEvent: 'click', // String: event to start slots on this event
onStart: $.noop, // Function: runs on spin start,
onEnd: $.noop, // Function:...