Our script provides a wrapper to the countup.js library allowing options to be specified as data attributes on counter elements.
Our wrapper works in conjunction with scrollMonitor to begin counting when the element is scrolled into view.
Despite its name, CountUp can count in either direction, depending on the parameters passed in.
Initializing
The demo pages already include the following code. These steps are only necessary if you are building a page from scratch. Remove these references if you are not using this plugin to improve page load times.
Load the initializer code in index.js
Countup is distributed as a CommonJS module, and must be embedded in theme.js. The import statement to embed the library is in js/mrare/countup.js.
Declare the following import statement in js/mrare/index.js. This ensures that the initializer code and CountUp library is included in the theme.js bundle.
import mrCountup from'./countup';
Ensure the following line appears in the export object:
export{
mrCountup,};
Basic Usage
Counters are initialized by data-attributes on page load.
Add the data-countup attribute to initialize the element as a counter.
By default, the counter will use the element's text and count up to that value from zero. The text is parsed by the javascript parseFloat function, so you may use a decimal or integer.
<spandata-countup>1234</span>
Advanced Usage
Counters are initialized by data-attributes on page load.
Add the data-countup attribute to initialize the element as a counter.