Skip to content

Instantly share code, notes, and snippets.

@mattsandersuk
Created July 31, 2019 08:06
Show Gist options
  • Save mattsandersuk/df384dfd482eb196222f2ba56b152863 to your computer and use it in GitHub Desktop.
Save mattsandersuk/df384dfd482eb196222f2ba56b152863 to your computer and use it in GitHub Desktop.
countUp Counter Widget - https://inorganik.github.io/countUp.js/
$( '.stat-counter' ).each(function() {
/**
*
* Get Vars from Data Attributes
*
*/
var numFrom = $(this).data('from'); // starting no.
var numTo = $(this).data('to'); // end no.
var numDec = $(this).data('dec'); // no. of dec places
var numSuffix = $(this).data('suffix');
var options = {
  useEasing : true,
  useGrouping : true,
  separator : ',',
  decimal : '.',
  prefix : '',
  suffix : numSuffix
};
var counter = new CountUp(this, numFrom, numTo, numDec, 2.5, options);
counter.start();
});
<div class="stat-counter-container">
<span class="stat-counter" data-dec="0" data-from="100" data-to="200">200</span>
<span class="stat-desc">Example Description</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment