• Stars
    star
    588
  • Rank 76,022 (Top 2 %)
  • Language
    TypeScript
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Makes Slot Machine effect without jquery (the name is just legacy O_O)

jQuery-SlotMachine Build Status Dependency Status devDependency Status

📣 jQuery is not neccessary now! The name it's just legacy.

A simple, and lightweight piece of code to make slot machine animation effect. It also exports a js wrapper to allow the usage with jQuery.

To preview what you can do check the example page!

slot-machine

Installation

Install the component using npm:

npm install jquery-slotmachine --save

yarn add jquery-slotmachine

Example

<div id="machine">
  <div>Madrid</div>
  <div>London</div>
  <div>New York</div>
</div>
const el = document.querySelector('#machine');

const machine = new SlotMachine(el, {
  active: 1,
  delay: 450
});

machine.shuffle();

Lookup the sourcecode in the examples page to see more examples.

Usage

Include the script located in dist folder:

<script src="/path/to/slotmachine.min.js"></script>

Or build your own package using a bundled (webpack, rollup, ...)

Then you can make it work calling the lib in your app:

const element = document.getElementById('my-machine');
const machine = new SlotMachine(element, {
  /* options */
});

Settings

Use the first argument of the function to pass an object with the options:

const machine = new SlotMachine(element, {
  active: 2,
  auto: true
});
Name Type Default Description
active Number 0 The initial visible element (0 means the first one)
delay Number 200 Duration (in ms) of each spin
randomize Function () => number Function (returns number) that returns the next active element (random value as default)
direction String up The spin direction (possible values are up and down)

Properties

  • machine.nextActive: Get the next active element (only while shuffling).
  • machine.nextIndex: Next element index according to the current direction.
  • machine.prevIndex: Prev element index according to the current direction.
  • machine.running: Check if the machine is running.
  • machine.stopping: Check if the machine is stopping.
  • machine.active: The current active element.

Methods

machine.shuffle(spins: number): Promise<void>: Starts spining the machine.

Arguments:

  • spins (Number): Optionally set the number of spins until stop.
// Do a single spin
machine.shuffle();
// Do 5 spins before stop
machine.shuffle(5);
// "Infinite" spins
machine.shuffle(Infinity);

machine.stop(spins: number): Promise<void>: Manually stops the machine.

Arguments:

  • spins (Number): Set the number of spins until stop. Use 0 to inmediate stop.
// Start spinning the machine
machine.shuffle(Infinity);
// Do 4 spins an then stop
machine.stop(4);

machine.next(): Promise<void>/machine.prev(): Promise<void>: Spins to the next/previous element.

// Spin to the previous element
machine.prev();

// Spin to the next element
machine.next();

Usefull recipes

To create an inifite carousel effect (as the previous versions run method) use a recursive function:

(async function run() {
  await machine.shuffle(5)
  await timeout(1000);
  run();
})();

Authors

Jose Luis Represa

License

jQuery-SlotMachine is released under the MIT License.

More Repositories

1

github-project-card

Polymer component to display github project data, like title, description, forks, ...
HTML
10
star
2

curso-nodejs-kairos

Curso de Node.js para Kairos
7
star
3

hexo-workbox

A plugin for your Hexo blog, giving your app offline caching as a progressive enhancement using service workers.
JavaScript
6
star
4

broccoli-workshop

Broccoli workshop
CSS
5
star
5

film-api

Aplicación hecha con expressjs para el Curso de NodeJS de @Fictizia;
JavaScript
3
star
6

vim-ale-playbulb

Change playbulb candle color while files are linted!
JavaScript
3
star
7

60fps-workshop

60fps-workshop
Pug
3
star
8

easyJS

Suite of jQuery plugins
JavaScript
3
star
9

markdown-toolbar

Atom markdown toolbar
CSS
3
star
10

dotfiles

dotfiles
Lua
3
star
11

firebase-login-express

Firebase login using express and cookies
JavaScript
2
star
12

gulp-example-spa

Aplicación hecha con gulp y React para el Curso de NodeJS de @Fictizia;
JavaScript
2
star
13

browser-bluetooth-lightbulb

Color picker for a bluetooth lightbulb in the browser
JavaScript
2
star
14

simple-chat

Aplicación hecha con expressjs y socket.io para el Curso de NodeJS de @Fictizia;
JavaScript
2
star
15

advent-of-code-2022

https://adventofcode.com/2022
TypeScript
2
star
16

fastapi_test

Python
1
star
17

mocha-example

Entorno de testing con mocha y eslint para el Curso de NodeJS de @Fictizia;
JavaScript
1
star
18

CSSBeautifier-Front

CSS
1
star
19

lit-element-hooks

Streaming data from web workers to lit-element components
JavaScript
1
star
20

twitter-firebase-stream

Ejercicios para aprender a trabajar con streams para el Curso de NodeJS de @Fictizia;
JavaScript
1
star
21

python_js

Some JS functions written in Python for learning purposes.
Python
1
star
22

Digital-Heroes-iOS

Objective-C
1
star
23

hubot-example

Ejercicios para aprender a montar un bot para el Curso de NodeJS de @Fictizia;
JavaScript
1
star
24

debug-exercises

Ejercicios para aprender a debugear para el Curso de NodeJS de @Fictizia;
JavaScript
1
star
25

download-video

Example of downloading + merge TS video parts for educational purposes
JavaScript
1
star
26

deno-graphql-gcp

Demo of a Graphql API running on Deno
HCL
1
star