npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@js4y/count-up

v1.1.3

Published

A tiny dependency-free JavaSript library for animating numeric values.

Downloads

276

Readme

Count up

A tiny dependency-free JavaSript library for animating numeric values.

Live Demo: https://bukacekd.github.io/count-up

Features

Installation

Npm

npm install @js4y/count-up

CDN

<script src="https://unpkg.com/@js4y/count-up/dist/index.js"></script>

Usage

Npm

import {CountUp} from '@js4y/count-up';

new CountUp(document.body, {
    from: 1,
    to: 10
});

CDN

<script src="https://unpkg.com/@js4y/count-up/dist/index.js"></script>

<script>
    new js4y.components.CountUp(document.body, {
    from: 1000,
    to: -1000
});
<script>

Configuration

The component offers a set of configuration items. Below is an overview of them.

new CountUp(element: HTMLElement | string, {
    begin?: Function,
    complete?: Function,
    duration?: number,
    easing?: Function,
    formattter?: Intl.NumberFormat,
    from: number,
    to: number,
    update?: Function
});

begin

required: false, type: Function

The callback function is triggered when the animation starts playing.

new CountUp(document.body, {
    begin: () => {
        console.log('start of animation');
    },
});

complete

required: false, type: Function

The callback function is triggered when the animation is completed.

new CountUp(document.body, {
    complete: () => {
        console.log('end of animation');
    },
});

duration

required: false, type: number

Animation duration in milliseconds.

new CountUp(document.body, {
    duration: 1000
});

easing

required: false, type: Function

A custom easing function of the animation. The function argument represents the animation progress between 0 (start of animation) and 1 (end of animation).

new CountUp(document.body, {
    easing: progress => Math.sin((progress * Math.PI) / 2),
});

Tip: Try one of the easing functions from the https://easings.net/.

formatter

required: false, type: Intl.NumberFormat

The number formatter. Allows wide formatting of numbers by locale. By default the formatting follows the html language of the page.

new Intl.NumberFormat(document.documentElement.lang, {
    maximumFractionDigits: 0,
    minimumFractionDigits: 0
});

To set up your own formatter follow the Intl.NumberFormatter documentation.

from

required: false, type: number

The beginning of the animation range.

new CountUp(document.body, {
    from: 10,
});

For numbers greater than Number.MAX_SAFE_INTEGER (253 - 1) use BigInt.

to

required: false, type: number

The end of animation range.

new CountUp(document.body, {
    to: 100,
});

For numbers greater than Number.MAX_SAFE_INTEGER (253 - 1) use BigInt.

update

required: false, type: Function

Callback function triggered on every frame as soon as the animation starts playing. The function argument represents the animation progress between 0 (start of animation) and 1 (end of animation).

new CountUp(document.body, {
    update: progress => {
        console.log('animation progress', progress.toFixed(2));
    },
});

Methods

create(element, options): CountUp

Creates the component, but without running the animation.

const countUp = CountUp.create(document.body, {
    duration: 1000,
    from: 1,
    to: 10
});

To start the animation, use the constructor.

const countUp = new CountUp(document.body, {
    duration: 1000,
    from: 1,
    to: 10
});

play(): void

The method starts playing the animation.

countUp.play();

pause(): void

The method pauses the animation.

countUp.pause();

cancel(): void

The method cancels the animation.

countUp.cancel();

Browser support

| alt chrome | alt edge | alt firefox | alt opera | alt safari | | :-: | :-: | :-: | :-: | :-: | | Chrome 24+ | Edge 12+ | Firefox 29+ | Opera 15+ | Safari 10+ |

License

The project is licensed under MIT license.

Related

  • Dialog - A tiny dependency-free JavaSript ES6 library built on a dialog element with minimal configuration.
  • Loader - A tiny dependency-free javascript loading spinner component with minimal configuration.
  • lockScroll - A set of methods to lock scrolling within an element or an entire page.