The bill counter effect is expressed in JavaScript.
See API Docs for details.
This library does not require any other libraries in production.
In development, we bundled with webpack.
<script src="https://unpkg.com/bill-counter-js@0.0.6/dist/bill-counter.min.js"></script>
yarn add bill-counter-js
or
npm install bill-counter-js -S
You must run the function after 'DOMContentLoaded' event.
Similar to jquery's $(document).ready().
DOMContentLoaded is a web standard and jQuery is not a web standard.
<script src="https://unpkg.com/bill-counter-js@0.0.6/dist/bill-counter.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
$B.countByN('selector-id', targetMoney, N, interval);
});
</script>
see example source
import { $B } from 'https://unpkg.com/bill-counter-js@0.0.6/dist/bill-counter.esm.js';
document.addEventListener('DOMContentLoaded', () => {
$B.countByN('selector-id', targetMoney, N, interval);
}
see example source
const { $B } = require('bill-counter-js');
$B.countByN('selector-id', targetMoney, N, interval);
$B.countByN(id, end, n, (interval = 0.1));
Count the numbers by n.
Perhaps most similar to the counter.
$B.countFast(id, end, (duration = 100));
Count any number in a certain amount of time.
I think it will be very effective as an animation.
The above two functions only worked for DOM objects. But sometimes you need to modify the Model, not the View, like Vue.js. Try using countObjectByN
or countObjectFast.
It is basically the same except that the first argument is object.
Copy the code below and run node source.js!
const { $B } = require('bill-counter-js');
const obj = {
value: 0,
};
$B.countObjectByN(obj, 1000, 1, (interval = 1));
function test() {
return new Promise(resolve => {
let i = 0;
const sid = setInterval(() => {
console.log(obj);
i++;
if (i === 1000) {
clearInterval(sid);
resolve();
}
}, 1);
});
}
(async () => {
await test();
})();
// default
$B.localeOptions = {
format: true,
locale: 'en-US',
currency: 'USD',
};
-
format: Do you format in currency? (true = yes)
-
locale: What language do you speak? (Learn More)
-
currency: What currency are you using? (Learn More)
The default formatter uses the ECMAScript Internationalization API. (INTL) If you don't like this, define your own formatter.
$B.formatStyler = (number) => {
// your formatter!
}
If you want to change back to the default style,
run $B.formatStyler = $B.defaultFormatStyler;
Try the demo here.