VanillaJS implementation of an animated rising / falling number.

Overview

number-rollup

npm bundle size npm npm npm

Demo

https://marknorrapscm.github.io/number-rollup/

Features

  • Smooth rising / falling number animations with easing options
  • VanillaJS
  • Zero dependencies
  • 1.3KB gzipped
  • No CSS; styling is under your control
  • Uses requestAnimationFrame() rather than setTimeout()
Note

Some browsers have options that implement anti-fingerprinting techniques which significantly reduce the millisecond accuracy of new Date() and performance.now(). These options are not enabled by default in Firefox (privacy.resistFingerprinting) or Chrome but, if they are, the animation won't run as smoothly.

Installation

npm install number-rollup --save

Usage

There are two ways to create animations.

Method A:

Invoke the method on an element-by-element basis.

<div id="example-1"></div>
import numberRollup from "number-rollup";

numberRollup({
	id: "example-1",
	startNumber: 0,
	endNumber: 500,
	duration: 500, // ms
	formatNumber: (s) => ${s}`, // optional
	easing: "easeIn" 			  // optional
});

Method B:

Apply class .number-rollup to one or more target elements and use data attributes to set the options. numberRollup() will find all elements with the class and apply the animation.

<button
	class="number-rollup"
	data-number-rollup-start="100"
	data-number-rollup-end="100000"
	data-number-rollup-duration="1000"
></button>
import numberRollup from "number-rollup";

numberRollup();

Options

id: string
The ID of the target element when creating a single animation.

startNumber: Number
The animation will roll from this number. Must be an integer.

endNumber: Number
The animation will roll to this number. Must be an integer.

duration: Number
The duration of the animation in milliseconds. Must be an integer.

formatNumber: function (optional)
A function that will be applied to the animated number each time before it is drawn. For example, turning 500 into $500. See the demo for a usage example.

easing: String (optional)
The easing function to be applied. Defaults to linear if none specified. Available options:

  • linear
  • easeIn
  • easeOut
  • easeInQuintic
  • easeOutQuintic
  • easeInOut
You might also like...

Animated Select Component (React)

Spring Chain We built a custom select component with a menu with animations and beautiful gradients and a glassy style, is called "Spring Chain" becau

Feb 6, 2022

Animated sprite hook for react-three-fiber

use-animated-sprite Animated sprite hook for react-three-fiber Dependencies npm install @react-three/drei @react-three/fiber react three Installation

Dec 4, 2022

Replaces native cursor with custom animated cursor.

Animated Cursor A pure JS library to replace native cursor with a custom animated cursor. Check out the Demo Contents 📌 Features 🎯 Quickstart 🧬 Opt

Jul 18, 2022

Animated Counter with Vanilla JavaScript

animated-counter [EN] Animated Counter with Vanilla JavaScript For this project, I used loop...of, but the funcionality still exactly the same See mor

Apr 6, 2022

Berlin subway map, animated

Berlin subway map, animated

Ubähnchen ubähnchen.vercel.app An animated live map of the Berlin U-Bahn. How it works Planned mode Schedules are extracted from the GTFS data of the

Dec 20, 2022

This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's cursor functionality.

This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's cursor functionality.

animatedWebCursors.js This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's

Dec 25, 2022

A JavaScript library to shuffle the text content of a DOM element with an animated effect.

shuffle-letters.js A JavaScript library to shuffle the text content of a DOM element with an animated effect. NOTE: This library is a port to vanilla

Jun 2, 2022

CPUSim is an open-source web-based animated x64 CPU simulator for educational purposes. Provided as a folder for easy distribution and without installation on the Google Chrome Browser. Powered by Unicorn.js, Capstone.js, Quasar and NASM.

CPUSim is an open-source web-based animated x64 CPU simulator for educational purposes. Provided as a folder for easy distribution and without installation on the Google Chrome Browser. Powered by Unicorn.js, Capstone.js, Quasar and NASM.

CPUSim - A Graphical CPU Simulator CPUSim is an open-source web-based animated x64 CPU simulator for educational purposes. Provided as a folder for ea

Oct 26, 2022

Displaying actual age in percentage with 9 signs after dot (floating number)

Displaying actual age in percentage with 9 signs after dot (floating number)

Actual Age Chrome Extension Displaying actual age in percentage with 9 signs after dot (floating number) Features Popup You can select your Birth date

Nov 2, 2022
Releases(v1.2.0)
  • v1.2.0(Mar 14, 2021)

    [1.2.0] - 2021-03-14

    Added

    • Easing functions

    Changed

    • Updated README.md
    • Code refactored
    • Removed Prettier and switched entirely to ESLint for formatting as well as linting
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Oct 28, 2020)

    [1.1.0] - 2020-10-24

    Added

    • Unit tests using Jest
    • CHANGELOG.md added

    Changed

    • Minor changes to README.md

    Fixed

    • Multiple animations will no longer run on the same element simultaneously
    Source code(tar.gz)
    Source code(zip)
Owner
Full stack .NET turned JS dev.
null
jquery-input-mask-phone-number.js - A simple, easy jquery format phone number mask library

jquery-input-mask-phone-number A jQuery Plugin to make masks on input field to US phone format. Quick start 1. Add latest jQuery and jquery-input-mask

Raja Rama Mohan Thavalam 12 Aug 25, 2022
A lightweight "Falling Sand Game" written in TypeScript

TechSquid Falling Sand Game | TSFSG A lightweight "Falling Sand Game" written in TypeScript with Pixi.js. Click to spawn particles of sand. TO DO: col

Kyle T 8 Aug 15, 2022
Simulating raindrops falling on a window

RainyDay.js A simple script for simulating raindrops falling on a glass surface. Project Page How to use Just add script to page and initilize RainyDa

Muhammad Ubaid Raza 89 Nov 7, 2022
💻 Application of an accountant from a falling in love dev

Hi there! ?? This project was developed with care and in the best way I could with the knowledge I have, I hope you enjoy it! ?? What is inside? Next

Giovanna Souza 2 Sep 6, 2022
This is an VanillaJS SPA example with function based rendering.

Function-Based-Rendering This is an VanillaJS SPA example with function based rendering. Here's how to create Views by function composition and how to

강호형 3 Oct 16, 2021
BVSelect-VanillaJS - BVSelect - Vanilla Javascript Fully Customizable SelectBox

BVSelect - Vanilla JS Replaces native select elements with fully customizable dropdowns. Demo: https://bmsvieira.github.io/BVSelect-VanillaJS/ Feature

Bruno Vieira 107 Dec 26, 2022
A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Jess Champion 2 Oct 3, 2020
Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support

JS Select Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support How to use To use the select plugins, two main file mu

Luigi Verolla 4 Mar 17, 2022
Planets fact site with animated solar system built with ReactJS.

Frontend Mentor - Planets fact site Table of contents Overview Intro The challenge Links My process Built with Features Setup Useful resources Overvie

null 72 Jan 1, 2023
A javascript library to generate animated wavy text!

Wavy Text Animation Library A JavaScript Library which allows you to animate infinite words in an infinite loop in a modern wavy way! Options Vanilla

Murtuzaali Surti 12 Oct 9, 2022