npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-slotmachine

v6.0.0

Published

> :mega: jQuery is not neccessary now! The name it's just legacy.

Downloads

261

Readme

jQuery-SlotMachine Build Status Dependency Status devDependency Status

:mega: 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.