Package Exports
- countup.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (countup.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
CountUp.js
CountUp.js is a dependency-free, lightweight Javascript class that can be used to quickly create animations that display numerical data in a more interesting way.
Despite its name, CountUp can count in either direction, depending on the start value and end value that you pass.
CountUp.js supports all browsers. MIT license.
Try the demo
New in 2.0.0
- Completely rewritten in Typescript! The distributed code is still Javascript.
- New cleaner method signature.
- Tests with Jest. As much code coverage as possible mocking requestAnimationFrame.
- Smart easing: CountUp intelligently defers easing until it gets close enough to the end value for easing to be visually noticeable. Configureable in the options.
- Separate bundles for with and without the requestAnimationFrame polyfill. Choose
countUp.min.js
for modern browsers orcountUp.withPolyfill.min.js
for IE9 and older, and Opera mini.
See Also
- CountUp.js Angular ^2 Module
- CountUp.js Angular 1.x Module
- CountUp.js React
- CountUp.js Vue component wrapper
- CountUp.js WordPress Plugin
- CountUp.js jQuery Plugin
Usage:
On npm: countup.js
Params:
target: string | HTMLElement | HTMLInputElement
- id of html element, input, svg text element, or DOM element reference where counting occursendVal: number
- the value you want to arrive atoptions?: CountUpOptions
- optional configuration object for fine-grain control
Options (defaults in parentheses):
interface CountUpOptions {
startVal?: number; // number to start at (0)
decimalPlaces?: number; // number of decimal places (0)
duration?: number; // animation duration in seconds (2)
useGrouping?: boolean; // example: 1,000 vs 1000 (true)
useEasing?: boolean; // ease animation (true)
smartEasingThreshold?: number; // smooth easing for large numbers above this if useEasing (999)
smartEasingAmount?: number; // amount to be eased for numbers above threshold (333)
separator?: string; // grouping separator (',')
decimal?: string; // decimal ('.')
// easingFn: easing function for animation (easeOutExpo)
easingFn?: (t: number, b: number, c: number, d: number) => number;
formattingFn?: (n: number) => string; // this function formats result
prefix?: string; // text prepended to result
suffix?: string; // text appended to result
numerals?: string[]; // numeral glyph substitution
}
const countUp = new CountUp('targetId', 5234);
if (!countUp.error) {
countUp.start();
} else {
console.error(countUp.error);
}
Pass options:
const countUp = new CountUp('targetId', 5234, options);
with optional callback:
countUp.start(someMethodToCallOnComplete);
// or an anonymous function
countUp.start(() => console.log('Complete!'));
Other methods:
Toggle pause/resume:
countUp.pauseResume();
Reset the animation:
countUp.reset();
Update the end value and animate:
countUp.update(989);
Contributing
Before you make a pull request, please be sure to follow these instructions:
- Do your work on
src/countUp.ts
- Test your work. Do manual tests on the demo in the browser and run
npm t
- Run
npm run build
, which copies and minifies the .js files to thedist
folder.