A jQuery plugin that animate the number dynamically.
- Main files
- Quick start
- Requirements
- Usage
- Examples
- Options
- Methods
- Events
- No conflict
- Browser support
- Contributing
- Development
- Changelog
- Copyright and license
dist/
├── jquery-dynamicNumber.js
├── jquery-dynamicNumber.es.js
└── jquery-dynamicNumber.min.js
Several quick start options are available:
- Development - unminified
- Production - minified
bower install jquery-dynamicNumber --save
npm install jquery-dynamicNumber --save
yarn add jquery-dynamicNumber
If you want build from source:
git clone [email protected]:amazingSurge/jquery-dynamicNumber.git
cd jquery-dynamicNumber
npm install
npm install -g gulp-cli babel-cli
gulp build
Done!
jquery-dynamicNumber
requires the latest version of jQuery
.
<script src="/path/to/jquery.js"></script>
<script src="/path/to/jquery-dynamicNumber.js"></script>
<span class="dynamicNumber" data-from="0" data-to="30">0</span>
<span class="dynamicNumber" data-from="0" data-to="30" data-decimals="2">0</span>
<span class="dynamicNumber" data-from="0" data-to="30" data-currency='{"indicator": "$"}' data-format="currency">$0</span>
<span class="dynamicNumber" data-from="0.00" data-to="10000.00" data-decimals="0" data-format="group">0</span>
<span class="dynamicNumber" data-from="0" data-to="30" data-format="percentage">0%</span>
<span class="dynamicNumber" data-from="0" data-to="30" data-format="custom_callback">%0</span>
All you need to do is call the plugin on the element:
jQuery(function($) {
$('.example').dynamicNumber();
});
There are some example usages that you can look at to get started. They can be found in the examples folder.
jquery-dynamicNumber
can accept an options object to alter the way it behaves. You can see the default options by call $.dynamicNumber.setDefaults()
. The structure of an options object is as follows:
{
namespace: '',
from: 0,
to: 100,
duration: 1000,
decimals: 0,
format: function(n, options) {
return n.toFixed(options.decimals);
},
percentage: {
decimals: 0
},
currency: {
indicator: '$',
size: 3,
decimals: '2',
separator: ',',
decimalsPoint: '.'
},
group: {
size: 3,
decimals: '2',
separator: ',',
decimalsPoint: '.'
}
}
Methods are called on dynamicNumber instances through the dynamicNumber method itself. You can also save the instances to variable for further use.
// call directly
$().dynamicNumber('start');
// or
var api = $().data('dynamicNumber');
api.start();
Start the number animate.
$().dynamicNumber('start');
Finish the number animate, and change the number to the goal.
$().dynamicNumber('finish');
Stop the number animate.
$().dynamicNumber('stop');
Reset the number to the first value.
$().dynamicNumber('reset');
Get the current number.
$().dynamicNumber('get');
Go to the number.
$().dynamicNumber('go', value);
Enable the number animate functions.
$().dynamicNumber('enable');
Disable the number animate functions.
$().dynamicNumber('disable');
Destroy the dynamic number instance.
$().dynamicNumber('destroy');
jquery-dynamicNumber
provides custom events for the plugin’s unique actions.
$('.the-element').on('dynamicNumber::ready', function (e) {
// on instance ready
});
Event | Description |
---|---|
init | Fires when the instance is setup for the first time. |
ready | Fires when the instance is ready for API use. |
update | Fires when the number value updated. |
start | Fires when the start instance method has been called. |
stop | Fires when the stop instance method has been called. |
reset | Fires when the reset instance method has been called. |
finish | Fires when the finish instance method has been called. |
enable | Fires when the enable instance method has been called. |
disable | Fires when the disable instance method has been called. |
destroy | Fires when an instance is destroyed. |
If you have to use other plugin with the same namespace, just call the $.dynamicNumber.noConflict
method to revert to it.
<script src="other-plugin.js"></script>
<script src="jquery-dynamicNumber.js"></script>
<script>
$.dynamicNumber.noConflict();
// Code that uses other plugin's "$().dynamicNumber" can follow here.
</script>
Tested on all major browsers.
Latest ✓ | Latest ✓ | Latest ✓ | Latest ✓ | 9-11 ✓ | Latest ✓ |
As a jQuery plugin, you also need to see the jQuery Browser Support.
Anyone and everyone is welcome to contribute. Please take a moment to
review the guidelines for contributing. Make sure you're using the latest version of jquery-dynamicNumber
before submitting an issue. There are several ways to help out:
- Bug reports
- Feature requests
- Pull requests
- Write test cases for open bug issues
- Contribute to the documentation
jquery-dynamicNumber
is built modularly and uses Gulp as a build system to build its distributable files. To install the necessary dependencies for the build system, please run:
npm install -g gulp
npm install -g babel-cli
npm install
Then you can generate new distributable files from the sources, using:
gulp build
More gulp tasks can be found here.
To see the list of recent changes, see Releases section.
Copyright (C) 2016 amazingSurge.
Licensed under the LGPL license.