Skip to content

Commit 464d062

Browse files
committed
fix active element
1 parent bdd2f60 commit 464d062

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

dist/slotmachine.js

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

dist/slotmachine.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,20 @@
7474
new SlotMachine(planeMachine, {
7575
active: 1,
7676
delay: 450,
77-
auto: 1500
77+
auto: 1500,
78+
randomize() {
79+
return this.nextIndex;
80+
}
7881
});
7982

8083
// Using jQuery
81-
$('#planeMachine').slotMachine({
84+
$('#planeMachine2').slotMachine({
8285
active: 1,
8386
delay: 450,
84-
auto: 1500
87+
auto: 1500,
88+
randomize() {
89+
return this.nextIndex;
90+
}
8591
});
8692
</script>
8793
</div>
@@ -363,7 +369,10 @@ <h1>Use the API</h1>
363369
$("#textMachine").slotMachine({
364370
active: 1,
365371
delay: 450,
366-
auto: 1500
372+
auto: 1500,
373+
randomize() {
374+
return this.nextIndex;
375+
}
367376
});
368377
</script>
369378
</div>

lib/slot-machine.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module.exports = class SlotMachine {
136136
get custom () {
137137
let choosen;
138138

139-
if (typeof this.randomize === 'function') {
139+
if (this.randomize) {
140140
let index = this.randomize(this.active);
141141
if (index < 0 || index >= this.tiles.length) {
142142
index = 0;
@@ -337,7 +337,7 @@ module.exports = class SlotMachine {
337337
this.running = true;
338338
this.stopping = true;
339339

340-
if (this.nextActive === null) {
340+
if (!Number.isInteger(this.nextActive)) {
341341
// Get random or custom element
342342
this.nextActive = this.custom;
343343
}
@@ -381,9 +381,6 @@ module.exports = class SlotMachine {
381381
}
382382

383383
this._timer = new Timer(() => {
384-
if (typeof this.randomize !== 'function') {
385-
this.randomize = () => this._nextIndex;
386-
}
387384
if (!this.visible && this.inViewport === true) {
388385
raf(() => {
389386
this._timer.reset()

0 commit comments

Comments
 (0)