Loading Dots is a jQuery plugin for “Loading...” behaviour, with incremental dots.
With bower: bower install jquery-loadingdots
.
Call loadingdots()
on your jQuery object. Takes optional parameters, which default to:
{
word: 'Loading', // String: Word prefixing the dots
dots: 3, // Number: Maximum number of dots
speed: 400 // Number: Time, in miliseconds, between dots increase
}
Examples:
// With default parameters
$('p').loadingdots();
// With custom parameters
$('p').loadingdots({ word: 'Processing', speed: 250 });
// You can set an empty string
$('p').loadingdots({ word: '', dots: 5 });
You can also set options via data-*
attributes:
data-loadingdots-word
: Word prefixig the dotsdata-loadingdots-dots
: Maximum number of dotsdata-loadingdots-speed
: Time, in miliseconds, between dots increase
Example:
<!-- Custom options -->
<p data-loadingdots-word="Processing" data-loadingdots-speed="250"></p>
<!-- You can set an empty string -->
<p data-loadingdots-word="" data-loadingdots-dots="5"></p>
Note: Setting options via data-loadingdots-*
attributes overrides options set with .loadingdots()
.
If you pass a string to loadingdots
after initializing it, you can control its behaviour.
Available methods:
pause
: Pauses the dots.play
: Resumes the dots.increment
: Manually increments one dot.stop
: Stops the dots (callspause
) and clears the element’s HTML content.start
: Builds the element’s HTML content and starts the dot (callsplay
)
Examples:
// Init
$('p').loadingdots();
// Immediately pause
$('p').loadingdots('pause');
// Manually increments one dot when button is pressed
$('button').on('click', function(){
$('p').loadingdots('increment');
});
You can customize the element and its contents with CSS with the following classes:
loading
: the target element itselfword
: the word prefixdots
: the dots
Example:
<p class="loading">
<span class="word">Loading</span>
<span class="dots">..</span>
</p>
Bonus: if dots are paused, the element has an additional paused
class.
<p class="loading paused">
<span class="word">Loading</span>
<span class="dots">..</span>
</p>
This plugin is based on a CSS-Tricks plugin from 2010: http://css-tricks.com/loading-dots-plugin/