2.0.0 • Published 6 years ago

@firstandthird/countup v2.0.0

Weekly downloads
15
License
MIT
Repository
github
Last release
6 years ago

CountUp npm

Easily animate numbers.

Installation

npm install --save @firstandthird/countup

Usage

CountUp has two exports. default one is a Domodule library and there's a named export by animateNumber which the Domodule library leverages.

animateNumber

This function takes an object with the following keys:

OptionTypeDefaultDescription
targetNumberN/AThe number you intend to reach by the end of the animation.
startNumber0The number the animation starts from.
durationNumberN/AThe amount of ms the animation should take.
callbackFunctionNoop FunctionFunction to be called once the animation finishes.
intervalFunctionN/AFunction to be called with every interval. Useful to update the DOM.

Example

import { animateNumber } from '@firstandthird/countup';

animateNumber({
  target: 20,
  interval: value => {
    someElement.innerHTML = value;
  }
});

CountUp module

CountUp has a module that can be used in the DOM and that also plays nice with ScrollTriggers.

OptionDefaultDescription
targetN/A Has to be definedThe number you intend to reach by the end of the animation.
start0The number the animation starts from.
durationN/AThe amount of ms the animation should take.
template'$D'Template to be used to format the number. $D will be replaced with the number. You could use $D% to animate a percent for example.

Example

<div data-module="Countup"
     data-module-target="20"
     data-module-template="$D%"></div>

See examples for more usage examples.

2.0.0

6 years ago

1.0.0

7 years ago