Code Monkey home page Code Monkey logo

spinner's Introduction

#spinner A JS character spinner for simple loading/processing indication. By default it chooses braille characters at random every 200ms. If there are any accessibility concerns with this (such as if you update the DOM with your spinner characters) please open an issue; I was not able to find any best practices concerning something like this.

If you are looking for a super small snippet version of this, check out my gist from which this developed: https://gist.github.com/rgrwkmn/6938952

##Dependencies Requires jQuery for its extend function but could easily be modified to not require it. Setup for use with AMD.

##Options

###callback A function to run for every spin. The current character is passed as an argument. ###speed How long in milliseconds to wait between each spin. ###random Whether or not to select a character at random or in order. ###characters A string of characters to spin. Comes default with the full set of Braille characters which create a fun effect when chosen at random.

##Methods

###start(callback) Start spinning immediately. If a callback is passed it will be set as the callback for each spin, otherwise it will use this.callback if set when creating the spinner. ###stop() Stop spinning.

##Examples Simple use with no options.

var Spinner = require('spinner');

var spinner = new Spinner();
spinner.start(function(char) {
     console.log(char);
});
//...later
spinner.stop();

Declare callback and speed options when creating the Spinner.

var spinner = new Spinner({
    speed: 250,
    callback: function(char) {
        console.log(char);
    }
});

spinner.start();

Custom characters per instance.

var spinner = new Spinner({
    characters: '|/-\\',
    callback: function(char) {
        console.log(char);
    }
})

spinner.start();

Method chaining.

var spinner = new Spinner().start(function(char) {
    console.log(char);
});

More than one character at a time.

var spinner = new Spinner({
    characters: ['.', '..', '...', '....'],
    random: false,
    callback: function(chars) {
        console.log('Loading'+char);
    }
}).start();

Updating the DOM

<span id="loading-indication">Loading</span>
var loadingIndication = document.getElementById('loading-indication');
var spinner = new Spinner({
    callback: function(char) {
        loadingIndication.innerHTML('Loading '+char);
    }
}).start();

spinner's People

Contributors

rgrwkmn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.